diff --git a/hibernate-core/src/test/java/org/hibernate/jpa/version/JpaSpecVersionValueUpdatingTest.java b/hibernate-core/src/test/java/org/hibernate/jpa/version/JpaSpecVersionValueUpdatingTest.java index e856854594..76b56ddd72 100644 --- a/hibernate-core/src/test/java/org/hibernate/jpa/version/JpaSpecVersionValueUpdatingTest.java +++ b/hibernate-core/src/test/java/org/hibernate/jpa/version/JpaSpecVersionValueUpdatingTest.java @@ -43,7 +43,56 @@ public class JpaSpecVersionValueUpdatingTest extends BaseCoreFunctionalTestCase } @Test - public void testVersionNotIncrementedOnModificationOfNonOwningCollection() { + public void testVersionNotIncrementedOnModificationOfNonOwningCollectionNonCascaded() { + Session session = openSession(); + session.beginTransaction(); + Customer customer = new Customer(); + customer.id = 1L; + session.save( customer ); + session.getTransaction().commit(); + session.close(); + + long initial = customer.version; + + session = openSession(); + session.beginTransaction(); + customer = (Customer) session.get( Customer.class, 1L ); + assertEquals( initial, customer.version ); + Order order = new Order(); + order.id = 1L; + order.customer = customer; + customer.orders.add( order ); + session.save( order ); + session.getTransaction().commit(); + session.close(); + + assertEquals( initial, customer.version ); + + session = openSession(); + session.beginTransaction(); + customer = (Customer) session.get( Customer.class, 1L ); + assertEquals( initial, customer.version ); + Order order2 = new Order(); + order2.id = 2L; + order2.customer = customer; + customer.orders.add( order2 ); + session.save( order2 ); + session.getTransaction().commit(); + session.close(); + + assertEquals( initial, customer.version ); + + session = openSession(); + session.beginTransaction(); + customer = (Customer) session.load( Customer.class, 1L ); + assertEquals( initial, customer.version ); + session.delete( customer ); + session.getTransaction().commit(); + session.close(); + } + + @Test + public void testVersionNotIncrementedOnModificationOfNonOwningCollectionCascaded() { Customer customer = new Customer(); customer.id = 1L;