rzo1 opened a new pull request, #224:
URL: https://github.com/apache/openjpa/pull/224

   https://issues.apache.org/jira/browse/OPENJPA-3024
   
   An element removed from a collection mapped with `orphanRemoval = true` and 
`cascade = CascadeType.ALL` (or `REMOVE`) was not deleted. On commit only the 
order column of the remaining elements was updated, and a new persistence 
context still found the removed element. Found by the Apache OpenMeetings 
tests; @solomax added `TestOpenJPA2330.testOrthanRemoval` for it in #223, and 
his two test commits are part of this PR.
   
   ## Cause
   
   Regression of OPENJPA-2940 (7eba99b9d, not released yet). 
`AnnotationPersistenceMetaDataParser.parseOneToOne()` and `parseOneToMany()` 
called `setOrphanRemoval()` before `setCascades()`, so the remove cascade 
replaced the dependent marking, and `StateManagerImpl.removed()` no longer 
deleted an element taken out of the collection. The merge in the test and the 
`equals`/`hashCode` of `EntityB` play no part; removing the element and 
committing fails the same way.
   
   ## Fix
   
   - `AnnotationPersistenceMetaDataParser`: apply the cascades first and orphan 
removal last again.
   - `SingleFieldManager.delete()`: when the owner is removed, a dependent 
value (single valued, map key, collection, array or map value) is removed right 
away, as for a remove cascade. Putting the parser order back alone breaks three 
tests in `TestEntityLifecycleTCK`, which OPENJPA-2940 added and which expect 
the children to be removed at `em.remove(parent)`. An element dropped from a 
collection of an owner that stays 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. Section 2.9 of the specification 
asks for this for orphan removal.
   
   ## Tests
   
   - `TestOpenJPA2330.testOrthanRemoval` fails on master and passes with the 
fix.
   - `TestEntityLifecycleTCK` still passes.
   - Full `openjpa-kernel` and `openjpa-persistence-jdbc` suites on Derby and 
H2.
   
   #223 can be rebased onto this once merged, which drops the test commits from 
it.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to