|
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!
|