Skip to content

Commit

Permalink
Fix test failure
Browse files Browse the repository at this point in the history
  • Loading branch information
sebersole committed Mar 9, 2022
1 parent 92686b1 commit 3a6ad2f
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 13 deletions.
6 changes: 2 additions & 4 deletions hibernate-core/src/main/java/org/hibernate/LockMode.java
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,8 @@ public static LockMode fromExternalForm(String externalForm) {
}
}

for ( LockMode lockMode : LockMode.values() ) {
if ( lockMode.externalForm.equalsIgnoreCase( externalForm ) ) {
return lockMode;
}
if ( externalForm.equalsIgnoreCase( "upgrade" ) ) {
return PESSIMISTIC_WRITE;
}

throw new IllegalArgumentException( "Unable to interpret LockMode reference from incoming external form : " + externalForm );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,21 +183,17 @@ public void testLockModeTypeWrite() {
final String initialName = "lock test";
// set up some test data
Item it = new Item();
MyEntity entity = new MyEntity();
inTransaction(
session -> {
it.setName( initialName );
session.save( it );
entity.setName( "Test" );
session.save( entity );
}
);

Long itemId = it.getId();
long initialVersion = it.getVersion();
Session s1 = null;
Session s2 = null;
MyEntity myEntity;
Item item;
try {
s1 = sessionFactory().openSession();
Expand All @@ -206,10 +202,6 @@ public void testLockModeTypeWrite() {
s1.lock( item, LockMode.PESSIMISTIC_FORCE_INCREMENT );
assertEquals( initialVersion + 1, item.getVersion(), "no forced version increment" );

myEntity = s1.get( MyEntity.class, entity.getId() );
s1.lock( myEntity, LockMode.PESSIMISTIC_FORCE_INCREMENT );
assertTrue( true, "LockMode.PESSIMISTIC_FORCE_INCREMENT on a un-versioned entity should degrade nicely to UPGRADE" );

s1.lock( item, LockMode.PESSIMISTIC_FORCE_INCREMENT );
assertEquals( initialVersion + 1, item.getVersion(), "subsequent LockMode.FORCE did not no-op" );

Expand Down Expand Up @@ -275,7 +267,6 @@ public void testLockModeTypeWrite() {
inTransaction(
session -> {
session.delete( item );
session.delete( myEntity );
}
);
}
Expand Down

0 comments on commit 3a6ad2f

Please sign in to comment.