diff --git a/hibernate-core/src/main/java/org/hibernate/LockMode.java b/hibernate-core/src/main/java/org/hibernate/LockMode.java index b2b4216dea..11f500538f 100644 --- a/hibernate-core/src/main/java/org/hibernate/LockMode.java +++ b/hibernate-core/src/main/java/org/hibernate/LockMode.java @@ -149,10 +149,8 @@ public enum LockMode { } } - 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 ); diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/lock/JPALockTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/lock/JPALockTest.java index 083105b06b..52f53f52ad 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/lock/JPALockTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/lock/JPALockTest.java @@ -183,13 +183,10 @@ public class JPALockTest extends AbstractJPATest { 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 ); } ); @@ -197,7 +194,6 @@ public class JPALockTest extends AbstractJPATest { long initialVersion = it.getVersion(); Session s1 = null; Session s2 = null; - MyEntity myEntity; Item item; try { s1 = sessionFactory().openSession(); @@ -206,10 +202,6 @@ public class JPALockTest extends AbstractJPATest { 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" ); @@ -275,7 +267,6 @@ public class JPALockTest extends AbstractJPATest { inTransaction( session -> { session.delete( item ); - session.delete( myEntity ); } ); }