HHH-5032 upgrade from optimistic to optimistic force does not work

git-svn-id: https://svn.jboss.org/repos/hibernate/core/trunk@19295 1b8cb986-b30d-0410-93ca-fae66ebed9b2
This commit is contained in:
Scott Marlow 2010-04-26 17:49:26 +00:00
parent 0ff854cabd
commit bc1acf7028
2 changed files with 24 additions and 2 deletions

View File

@ -3225,8 +3225,8 @@ public abstract class AbstractEntityPersister
readLoader : readLoader :
createEntityLoader( LockMode.PESSIMISTIC_FORCE_INCREMENT ) createEntityLoader( LockMode.PESSIMISTIC_FORCE_INCREMENT )
); );
loaders.put( LockMode.OPTIMISTIC, readLoader ); loaders.put( LockMode.OPTIMISTIC, createEntityLoader( LockMode.OPTIMISTIC) );
loaders.put( LockMode.OPTIMISTIC_FORCE_INCREMENT, readLoader ); loaders.put( LockMode.OPTIMISTIC_FORCE_INCREMENT, createEntityLoader(LockMode.OPTIMISTIC_FORCE_INCREMENT) );
loaders.put( loaders.put(
"merge", "merge",

View File

@ -210,6 +210,28 @@ public class LockTest extends TestCase {
em.close(); em.close();
} }
public void testLockOptimisticForceIncrementDifferentEm() throws Exception {
Lock lock = new Lock();
lock.setName( "force" );
EntityManager em1 = createIsolatedEntityManager();
em1.getTransaction().begin();
em1.persist( lock );
em1.getTransaction().commit();
em1.close();
EntityManager em2 = createIsolatedEntityManager();
em2.getTransaction().begin();
lock = em2.find( Lock.class, lock.getId(), LockModeType.OPTIMISTIC );
assertEquals( "lock mode should be OPTIMISTIC ", LockModeType.OPTIMISTIC, em2.getLockMode(lock) );
em2.lock( lock, LockModeType.OPTIMISTIC_FORCE_INCREMENT );
assertEquals( "lock mode should be OPTIMISTIC_FORCE_INCREMENT ", LockModeType.OPTIMISTIC_FORCE_INCREMENT, em2.getLockMode(lock) );
em2.getTransaction().commit();
em2.getTransaction().begin();
em2.remove( lock );
em2.getTransaction().commit();
em2.close();
}
public void testContendedPessimisticLock() throws Exception { public void testContendedPessimisticLock() throws Exception {
EntityManager em = getOrCreateEntityManager(); EntityManager em = getOrCreateEntityManager();