HHH-9419 : Remove after get with optimistic lock fails

(cherry picked from commit c80a8c442a)
This commit is contained in:
Arcadiy Ivanov 2014-09-27 02:19:01 -04:00 committed by Gail Badner
parent b8923b1e39
commit 5047f6fcc6
2 changed files with 30 additions and 0 deletions

View File

@ -55,6 +55,11 @@ public class EntityVerifyVersionProcess implements BeforeTransactionCompletionPr
public void doBeforeTransactionCompletion(SessionImplementor session) {
final EntityPersister persister = entry.getPersister();
if ( !entry.isExistsInDatabase() ) {
// HHH-9419: We cannot check for a version of an entry we ourselves deleted
return;
}
final Object latestVersion = persister.getCurrentVersion( entry.getId(), session );
if ( !entry.getVersion().equals( latestVersion ) ) {
throw new OptimisticLockException(

View File

@ -293,6 +293,31 @@ public class QueryLockingTest extends BaseEntityManagerFunctionalTestCase {
em.close();
}
@Test
@TestForIssue(jiraKey = "HHH-9419")
public void testNoVersionCheckAfterRemove() {
EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
Lockable lock = new Lockable( "name" );
em.persist( lock );
em.getTransaction().commit();
em.close();
Integer initial = lock.getVersion();
assertNotNull( initial );
em = getOrCreateEntityManager();
em.getTransaction().begin();
Lockable reread = em.createQuery( "from Lockable", Lockable.class )
.setLockMode( LockModeType.OPTIMISTIC )
.getSingleResult();
assertEquals( initial, reread.getVersion() );
assertTrue( em.unwrap( SessionImpl.class ).getActionQueue().hasBeforeTransactionActions() );
em.remove( reread );
em.getTransaction().commit();
em.close();
assertEquals( initial, reread.getVersion() );
}
@Test
public void testOptimisticSpecific() {
EntityManager em = getOrCreateEntityManager();