diff --git a/hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/dirty/DirtyTrackingTest.java b/hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/dirty/DirtyTrackingTest.java index e16acebeae61..af037f87419b 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/dirty/DirtyTrackingTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/dirty/DirtyTrackingTest.java @@ -63,11 +63,20 @@ public void test() { EnhancerTestUtils.checkDirtyTracking( entity, "someStrings" ); EnhancerTestUtils.clearDirtyTracking( entity ); - // Association: this should not set the entity to dirty - Set intSet = new HashSet<>(); - intSet.add( 42 ); - entity.someInts = intSet; + // Association, 1: creating the association will mark it dirty + Set associatedSet = new HashSet<>(); + OtherEntity o = new OtherEntity(); + o.id = 1l; + o.name = "other"; + associatedSet.add( o ); + entity.someAssociation = associatedSet; + EnhancerTestUtils.checkDirtyTracking( entity, "someAssociation" ); + EnhancerTestUtils.clearDirtyTracking( entity ); + + // Association, 2: modifying a related entity should not + o.name = "newName"; EnhancerTestUtils.checkDirtyTracking( entity ); + EnhancerTestUtils.checkDirtyTracking( o, "name" ); // testing composite object Address address = new Address(); @@ -125,7 +134,7 @@ private static class SimpleEntity { List someStrings; @OneToMany - Set someInts; + Set someAssociation; @Embedded Address address; @@ -141,4 +150,11 @@ public void setSomeNumber(Long someNumber) { this.someNumber = someNumber; } } + + @Entity + private static class OtherEntity { + @Id + Long id; + String name; + } } \ No newline at end of file