Skip to content

Commit

Permalink
HHH-9419 : Remove after get with optimistic lock fails
Browse files Browse the repository at this point in the history
(cherry picked from commit 3ee73a8)
  • Loading branch information
arcivanov authored and gbadner committed Jan 6, 2015
1 parent 4506987 commit f515019
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ public EntityVerifyVersionProcess(Object object, EntityEntry entry) {
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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,31 @@ public void testOptimisticOverall() {
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();
Expand Down

0 comments on commit f515019

Please sign in to comment.