Inconsistent behavior on *toMany collections if versions are negative
Description
Activity
Show:
Luz November 26, 2019 at 11:35 AM
This bug avoids to visit the collections before save and wrap them in PersistentCollections.
This effectively breaks the deleteOrphan feature, and violates the JPA spec.
Andreas Benneke October 28, 2015 at 11:17 AM
Verified that the behavior still exists in 4.3.11 und 5.0.2.
Andreas Benneke July 18, 2015 at 2:42 PM
This issue still exists with 5.0.0.CR2.
Details
Details
Assignee
Unassigned
UnassignedReporter
Andreas Benneke
Andreas BennekeComponents
Priority
Created July 18, 2015 at 10:48 AM
Updated November 26, 2019 at 12:47 PM
If you persist or merge a versioned entity it depends on the initial version whether the *toMany collections are replaced with their persistent implementations or not.
If the version is non-negative, the persistent implementations are in place.
If the version is negative, the original implementations are still in place.
Hibernate handles both cases later during flush and I was not able to create a scenario where this inconsistency leads to a problem, but it is still inconsistent.
I think I've spotted the problem in
AbstractSaveEventListener.performSaveOrReplicate
:if ( persister.hasCollections() ) { substitute = substitute || visitCollectionsBeforeSave( entity, id, values, types, source ); }
IMHO should be
if ( persister.hasCollections() ) { substitute = visitCollectionsBeforeSave( entity, id, values, types, source ) || substitute; }
You may find a small stripped down test project on Github https://github.com/abenneke/sandbox/tree/master/hibernate-versions which includes a
NegativeVersionTest
Thank you!