Skip to content

Commit f549b88

Browse files
committed
HHH-9171 : Orphan removal does not happen for new entity element
1 parent 1fc74fe commit f549b88

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

hibernate-core/src/test/java/org/hibernate/test/orphan/OrphanTest.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import org.hibernate.Transaction;
3232
import org.hibernate.internal.util.SerializationHelper;
3333
import org.hibernate.testing.FailureExpected;
34+
import org.hibernate.testing.TestForIssue;
3435
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
3536

3637
import static org.junit.Assert.assertNotNull;
@@ -362,7 +363,7 @@ public void testOrphanDeleteOnMergeRemoveElementMerge() {
362363

363364
@Test
364365
@SuppressWarnings( {"unchecked"})
365-
@FailureExpected(jiraKey = "HHH-9171")
366+
@TestForIssue(jiraKey = "HHH-9171")
366367
public void testOrphanDeleteOnAddElementMergeRemoveElementMerge() {
367368
Session session = openSession();
368369
Transaction t = session.beginTransaction();
@@ -380,14 +381,19 @@ public void testOrphanDeleteOnAddElementMergeRemoveElementMerge() {
380381
session = openSession();
381382
t = session.beginTransaction();
382383
session.merge(prod);
384+
// In Section 2.9, Entity Relationships, the JPA 2.1 spec says:
385+
// "If the entity being orphaned is a detached, new, or removed entity,
386+
// the semantics of orphanRemoval do not apply."
387+
// In other words, since part is a new entity, it will not be deleted when removed
388+
// from prod.parts, even though cascade for the association includes "delete-orphan".
383389
prod.getParts().remove(part);
384390
session.merge( prod );
385391
t.commit();
386392
session.close();
387393

388394
session = openSession();
389395
t = session.beginTransaction();
390-
assertNull( session.get( Part.class, "Widge" ) );
396+
assertNotNull( session.get( Part.class, "Widge" ) );
391397
session.delete( session.get(Product.class, "Widget") );
392398
t.commit();
393399
session.close();

0 commit comments

Comments
 (0)