31
31
import org .hibernate .Transaction ;
32
32
import org .hibernate .internal .util .SerializationHelper ;
33
33
import org .hibernate .testing .FailureExpected ;
34
+ import org .hibernate .testing .TestForIssue ;
34
35
import org .hibernate .testing .junit4 .BaseCoreFunctionalTestCase ;
35
36
36
37
import static org .junit .Assert .assertNotNull ;
@@ -362,7 +363,7 @@ public void testOrphanDeleteOnMergeRemoveElementMerge() {
362
363
363
364
@ Test
364
365
@ SuppressWarnings ( {"unchecked" })
365
- @ FailureExpected (jiraKey = "HHH-9171" )
366
+ @ TestForIssue (jiraKey = "HHH-9171" )
366
367
public void testOrphanDeleteOnAddElementMergeRemoveElementMerge () {
367
368
Session session = openSession ();
368
369
Transaction t = session .beginTransaction ();
@@ -380,14 +381,19 @@ public void testOrphanDeleteOnAddElementMergeRemoveElementMerge() {
380
381
session = openSession ();
381
382
t = session .beginTransaction ();
382
383
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".
383
389
prod .getParts ().remove (part );
384
390
session .merge ( prod );
385
391
t .commit ();
386
392
session .close ();
387
393
388
394
session = openSession ();
389
395
t = session .beginTransaction ();
390
- assertNull ( session .get ( Part .class , "Widge" ) );
396
+ assertNotNull ( session .get ( Part .class , "Widge" ) );
391
397
session .delete ( session .get (Product .class , "Widget" ) );
392
398
t .commit ();
393
399
session .close ();
0 commit comments