Richard Zowalla created OPENJPA-3024:
----------------------------------------
Summary: An element removed from a collection with orphanRemoval
and cascade remove is not deleted
Key: OPENJPA-3024
URL: https://issues.apache.org/jira/browse/OPENJPA-3024
Project: OpenJPA
Issue Type: Bug
Reporter: Richard Zowalla
Assignee: Richard Zowalla
An element removed from a collection with {{orphanRemoval = true}} and
{{cascade = CascadeType.ALL}} (or {{REMOVE}}) is not deleted. On commit only
the order column of the remaining elements is updated, no {{DELETE}} is issued,
and a new persistence context still finds the removed element in the collection.
{code:java}
@OneToMany(mappedBy = "center", orphanRemoval = true, cascade = CascadeType.ALL)
private List<EntityB> services;
{code}
{code:java}
em.getTransaction().begin();
EntityA a = em.find(EntityA.class, id); // 3 Bs
a.getBs().remove(a.getBs().iterator().next());
em.getTransaction().commit();
// new EntityManager
em2.find(EntityA.class, id).getBs().size(); // 3, expected 2
{code}
Found by the Apache OpenMeetings tests; Maxim Solodovnik added a test for it to
the OPENJPA-3019 pull request ({{TestOpenJPA2330.testOrthanRemoval}}).
This is a regression of OPENJPA-2940 (commit 7eba99b9d), which is not in a
release yet. {{AnnotationPersistenceMetaDataParser.parseOneToOne()}} and
{{parseOneToMany()}} now call {{setOrphanRemoval()}} before {{setCascades()}},
so on a relation with both, the remove cascade replaces the dependent marking
and {{StateManagerImpl.removed()}} no longer deletes an element taken out of
the collection.
Putting {{setOrphanRemoval()}} last again is not enough: OPENJPA-2940 changed
the order so that the children of a removed owner are removed at
{{em.remove(parent)}}, as {{TestEntityLifecycleTCK}} checks. So
{{SingleFieldManager.delete()}} also has to remove a dependent value right away
when its owner is removed, as section 2.9 of the specification asks for orphan
removal, while an element dropped from a collection of a remaining owner is
still deleted at flush.
Behaviour change: the children of a removed owner on an orphan removal or
{{@Dependent}} relation become removed, and get their remove callbacks, at
{{remove()}} of the owner instead of at flush.
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)