I have also encountered the problem that the previous and current states for a collection are identical (the updated state) in the onFlushDirty interceptor.
My guess is that hibernate only keeps track of references, so that when you modify the collection, you are not changing the 'previous' reference and thus it still points to the modified collection.
A workaround for this is to create a new instance of the collection class whenever you want to modify it. If you're worried about allocating a new object each time, then track when you have the hibernate implementation class and allocate a new collection only then. The previous state will then reference the old hibernate collection and the current state your newly allocated one.
Note however that reallocating hibernate collections is generally considered bad form and won't work for an all-delete-orphan cascade.
|