org.hibernate.test.jpa.lock
Class JPALockTest

java.lang.Object
  extended by org.hibernate.testing.junit4.BaseUnitTestCase
      extended by org.hibernate.testing.junit4.BaseCoreFunctionalTestCase
          extended by org.hibernate.test.jpa.AbstractJPATest
              extended by org.hibernate.test.jpa.lock.JPALockTest

public class JPALockTest
extends AbstractJPATest

Tests specifically relating to section 3.3.5.3 [Lock Modes] of the JPA persistence specification (as of the Proposed Final Draft).


Nested Class Summary
 
Nested classes/interfaces inherited from class org.hibernate.test.jpa.AbstractJPATest
AbstractJPATest.JPAAutoFlushEventListener, AbstractJPATest.JPAFlushEntityEventListener, AbstractJPATest.JPAFlushEventListener, AbstractJPATest.JPAPersistEventListener, AbstractJPATest.JPAPersistOnFlushEventListener
 
Nested classes/interfaces inherited from class org.hibernate.testing.junit4.BaseCoreFunctionalTestCase
BaseCoreFunctionalTestCase.RollbackWork
 
Field Summary
 
Fields inherited from class org.hibernate.testing.junit4.BaseCoreFunctionalTestCase
DIALECT, NO_CLASSES, NO_MAPPINGS, USE_NEW_METADATA_MAPPINGS, VALIDATE_DATA_CLEANUP
 
Constructor Summary
JPALockTest()
           
 
Method Summary
 void testLockModeTypeRead()
          Test the equivalent of EJB3 LockModeType.READ

From the spec:

If transaction T1 calls lock(entity, LockModeType.READ) on a versioned object, the entity manager must ensure that neither of the following phenomena can occur: P1 (Dirty read): Transaction T1 modifies a row.

 void testLockModeTypeWrite()
          Test the equivalent of EJB3 LockModeType.WRITE

From the spec:

If transaction T1 calls lock(entity, LockModeType.WRITE) on a versioned object, the entity manager must avoid the phenomena P1 and P2 (as with LockModeType.READ) and must also force an update (increment) to the entity's version column.

 
Methods inherited from class org.hibernate.test.jpa.AbstractJPATest
buildAutoFlushEventListeners, buildFlushEntityEventListeners, buildFlushEventListeners, buildPersisOnFlushEventListeners, buildPersistEventListeners, configure, getCacheConcurrencyStrategy, getMappings, prepareBootstrapRegistryBuilder
 
Methods inherited from class org.hibernate.testing.junit4.BaseCoreFunctionalTestCase
addMappings, addMappings, afterConfigurationBuilt, afterConfigurationBuilt, afterSessionFactoryBuilt, afterTest, applyCacheSettings, assertAllDataRemoved, beforeTest, buildConfiguration, buildServiceRegistry, cleanupCache, cleanupTest, configuration, constructConfiguration, createSchema, generateBootstrapRegistry, getAnnotatedClasses, getAnnotatedPackages, getBaseForMappings, getDialect, getXmlFiles, onFailure, openSession, openSession, overrideCacheStrategy, prepareBasicRegistryBuilder, prepareTest, readCommittedIsolationMaintained, rebuildSessionFactory, rebuildSessionFactoryOnError, serviceRegistry, sessionFactory
 
Methods inherited from class org.hibernate.testing.junit4.BaseUnitTestCase
releaseTransactions
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JPALockTest

public JPALockTest()
Method Detail

testLockModeTypeRead

public void testLockModeTypeRead()
Test the equivalent of EJB3 LockModeType.READ

From the spec:

If transaction T1 calls lock(entity, LockModeType.READ) on a versioned object, the entity manager must ensure that neither of the following phenomena can occur:


testLockModeTypeWrite

public void testLockModeTypeWrite()
Test the equivalent of EJB3 LockModeType.WRITE

From the spec:

If transaction T1 calls lock(entity, LockModeType.WRITE) on a versioned object, the entity manager must avoid the phenomena P1 and P2 (as with LockModeType.READ) and must also force an update (increment) to the entity's version column. A forced version update may be performed immediately, or may be deferred until a flush or commit. If an entity is removed before a deferred version update was to have been applied, the forced version update is omitted, since the underlying database row no longer exists.

The persistence implementation is not required to support calling lock(entity, LockMode-Type.WRITE) on a non-versioned object. When it cannot support a such lock call, it must throw the PersistenceException. When supported, whether for versioned or non-versioned objects, LockMode-Type.WRITE must always prevent the phenomena P1 and P2. For non-versioned objects, whether or not LockModeType.WRITE has any additional behaviour is vendor-specific. Applications that call lock(entity, LockModeType.WRITE) on non-versioned objects will not be portable.

Due to the requirement that LockModeType.WRITE needs to force a version increment, a new Hibernate LockMode was added to support this behavior: LockMode.FORCE.



Copyright © 2001-2012 Red Hat, Inc. All Rights Reserved.