I have some hibernate code that performs an insert into the database, and on completion of that insert a customized PostInsertEventListener is fired. (Essentially a trigger to ensure that other records are updated appropriately)
What I need to do is make the code inside the EventListener use the same transaction as the original insert, so that if the insert does not commit successfully, the EventListener will not fire.
I have heard that you can use javax.transaction.Syncronization
and Hibernate's transaction.registerSyncronization()
methods to do this, but there is no examples of usage anywhere that I can find.
Any help is appreciated.