I am developing a post commit notification system and need to be able to see the before, after and dirty fields data of a commit (as approprpriate)
I have implemented the PostCommitInsertListener and PostCommitDeleteListener and they work as expected. I.E. an insert (via save) invokes the PostCommitInsertListener and a delete (via remove) invokes the PostCommitDeleteListener.(after the commit of course)
However, after a merge, I the only get a MergeEventListener, FlushEntityEventListener and a FlushEventListener to fire. None of these provide the data I require. The commit does not seem to cause the PostUpdateCommitListener to fire, which does contain what I need.
I am “stuck” with using merge for the time being, so I can not change to use session.update().
Is there any way to solve this?
As a test I implemented a Listener for each and every event that does nothing more that print “invoked” so I know when which are firing.
the test case
first deletes any existing row by key (so I can repeat the test),
then inserts a record via save with commit
then tries to update the record via merge with commit
then deletes the record via remove with commit
the following Listener implementions are called:
removing existing entity from database
PersistencePostLoadEventListener invoked
PersistenceDeleteEventListener invoked
PersistenceFlushEntityEventListener invoked
PersistencePreCollectionRemoveEventListener invoked
PersistencePostCollectionRemoveEventListener invoked
PersistencePreDeleteEventListener invoked
PersistencePostDeleteEventListener invoked
PersistenceFlushEventListener invoked
PersistencePostDeleteCommitEventListener invoked
PersistenceClearEventListener invoked
... DONE
creating new entity in the database
PersistenceSaveOrUpdateListener invoked
PersistenceFlushEntityEventListener invoked
PersistencePreInsertEventListener invoked
PersistencePostInsertEventListener invoked
PersistencePreCollectionRecreateEventListener invoked
PersistencePostCollectionRecreateEventListener invoked
PersistenceFlushEventListener invoked
PersistencePostInsertCommitEventListener invoked
... DONE
updating entity in the database
PersistenceMergeEventListener invoked
PersistenceFlushEntityEventListener invoked
PersistenceFlushEventListener invoked
... DONE
deleting entity in the database
PersistenceDeleteEventListener invoked
PersistenceFlushEntityEventListener invoked
PersistencePreCollectionRemoveEventListener invoked
PersistencePostCollectionRemoveEventListener invoked
PersistencePreDeleteEventListener invoked
PersistencePostDeleteEventListener invoked
PersistenceFlushEventListener invoked
PersistencePostDeleteCommitEventListener invoked
... DONE