For merge, a PreCollectionUpdateEvent is fired, which basically is able to determine that the collection changed and proceeds to apply a DEL entry for the Child instance that was removed when the collection was replaced. In other words, merge is able to compare the old collection against the new collection and determines the difference For saveOrUpdate, the problem is that the first event raised is a PreCollectionRemoveEvent. If the entity is detached, the collection entry associated with the Parent entity isn't available, so this event is basically skipped. If the entity were attached, the collection entry is available, allowing the event to trigger the proper DEL entry for the removed element when the subsequent PostCollectionRecreateEvent is fired. One workaround would be that if you're going to be working with detached entities, use the JPA methods persist and merge. |