From 436206356f3582559684f167532fcceae39b0bea Mon Sep 17 00:00:00 2001 From: Gail Badner Date: Tue, 27 May 2014 12:19:04 -0700 Subject: [PATCH] HHH-9171 : Orphan removal does not happen for new entity element --- .../java/org/hibernate/test/orphan/OrphanTest.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/hibernate-core/src/test/java/org/hibernate/test/orphan/OrphanTest.java b/hibernate-core/src/test/java/org/hibernate/test/orphan/OrphanTest.java index 753d5615db4f..f0b197814cd3 100755 --- a/hibernate-core/src/test/java/org/hibernate/test/orphan/OrphanTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/orphan/OrphanTest.java @@ -31,6 +31,7 @@ import org.hibernate.Transaction; import org.hibernate.internal.util.SerializationHelper; import org.hibernate.testing.FailureExpected; +import org.hibernate.testing.TestForIssue; import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; import static org.junit.Assert.assertNotNull; @@ -362,7 +363,7 @@ public void testOrphanDeleteOnMergeRemoveElementMerge() { @Test @SuppressWarnings( {"unchecked"}) - @FailureExpected(jiraKey = "HHH-9171") + @TestForIssue(jiraKey = "HHH-9171") public void testOrphanDeleteOnAddElementMergeRemoveElementMerge() { Session session = openSession(); Transaction t = session.beginTransaction(); @@ -380,6 +381,11 @@ public void testOrphanDeleteOnAddElementMergeRemoveElementMerge() { session = openSession(); t = session.beginTransaction(); session.merge(prod); + // In Section 2.9, Entity Relationships, the JPA 2.1 spec says: + // "If the entity being orphaned is a detached, new, or removed entity, + // the semantics of orphanRemoval do not apply." + // In other words, since part is a new entity, it will not be deleted when removed + // from prod.parts, even though cascade for the association includes "delete-orphan". prod.getParts().remove(part); session.merge( prod ); t.commit(); @@ -387,7 +393,7 @@ public void testOrphanDeleteOnAddElementMergeRemoveElementMerge() { session = openSession(); t = session.beginTransaction(); - assertNull( session.get( Part.class, "Widge" ) ); + assertNotNull( session.get( Part.class, "Widge" ) ); session.delete( session.get(Product.class, "Widget") ); t.commit(); session.close();