I think I see what's going on. The collection in question is a @CollectionOfElements, so its lifecycle is entirely managed by the containing entity. I updated the collection by calling PlainEntity.setSomeCollection(new set). This orphaned the old collection. When Envers is wired in, it seems to disturb things around that the flushes execute the operations in the wrong order:
1. First, the new collection elements are inserted.
2. Later, somewhere during AuditSync.beforeCompletion, Hibernate realizes that the old collection was removed and notes this in the session's ActionQueue. It eventually issues a delete from ... statement. This leaves me with an empty collection.
I changed the collection operation to do:
plainEntity.getSomeCollection().clear(); plainEntity.getSomeCollection().addAll(new set);
That seems to work around the problem. Unfortunately, I don't really have the time to poke into this further to file a proper bug report. I thought I'd just write this followup to my original post in case it helps.
|