Updating a lazy loaded bidirectional collection may cause a NonUniqueObjectException when multiple references are referencing the same target.
If the target is not yet loaded for the first reference found and the target entity involves inheritance session.bestGuessEntityName in BaseEnversEventListener.addCollectionChangeWorkUnit may return the base entity name. For the second reference this will return the proper instance class as then the entity is loaded. This causes the deduplication check in addWorkUnit to fail and we end up with two entries sharing the same id in the audit table.
Proper fix seems to be to force the entity load before calling bestGuessEntityName (it is loaded directly afterwards anyways).
|