From bc1acf702863519d3d8a2c2282b08d2285cb7a3e Mon Sep 17 00:00:00 2001 From: Scott Marlow Date: Mon, 26 Apr 2010 17:49:26 +0000 Subject: [PATCH] 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 --- .../entity/AbstractEntityPersister.java | 4 ++-- .../org/hibernate/ejb/test/lock/LockTest.java | 22 +++++++++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/org/hibernate/persister/entity/AbstractEntityPersister.java b/core/src/main/java/org/hibernate/persister/entity/AbstractEntityPersister.java index 367252eb07..429b27cd75 100644 --- a/core/src/main/java/org/hibernate/persister/entity/AbstractEntityPersister.java +++ b/core/src/main/java/org/hibernate/persister/entity/AbstractEntityPersister.java @@ -3225,8 +3225,8 @@ public abstract class AbstractEntityPersister readLoader : createEntityLoader( LockMode.PESSIMISTIC_FORCE_INCREMENT ) ); - loaders.put( LockMode.OPTIMISTIC, readLoader ); - loaders.put( LockMode.OPTIMISTIC_FORCE_INCREMENT, readLoader ); + loaders.put( LockMode.OPTIMISTIC, createEntityLoader( LockMode.OPTIMISTIC) ); + loaders.put( LockMode.OPTIMISTIC_FORCE_INCREMENT, createEntityLoader(LockMode.OPTIMISTIC_FORCE_INCREMENT) ); loaders.put( "merge", diff --git a/entitymanager/src/test/java/org/hibernate/ejb/test/lock/LockTest.java b/entitymanager/src/test/java/org/hibernate/ejb/test/lock/LockTest.java index 41b7484f6b..fe5d698eb0 100644 --- a/entitymanager/src/test/java/org/hibernate/ejb/test/lock/LockTest.java +++ b/entitymanager/src/test/java/org/hibernate/ejb/test/lock/LockTest.java @@ -210,6 +210,28 @@ public class LockTest extends TestCase { 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 { EntityManager em = getOrCreateEntityManager();