Hi, I'm trying to perform a specific action upon transaction rollback.
Assuming this could be done using a custom javax.transaction.Synchronization, I tried to register a synchronization as follows: TransactionImplementor transaction = ...; // e.g. a CMTTransaction transaction.registerSynchronization( new MySync() ); And indeed beforeCompletion() is invoked as expected. But afterCompletion() never is. I debugged this a bit on WildFly and observed the following: * Hibernate ORM registers RegisteredSynchronization with JTA. RegisteredSynchronization manages (indirectly, through TransactionCoordinator, SynchronizationRegistry etc.) those synchronizations added through o.h.t.Transaction.registerSynchronization() * WildFly (specifically, TransactionUtil [1]) registers its own SessionSynchronization for closing the entity manager/session Now that second synchronization is called first, closing the session. Upon SessionImpl#close(), the SynchronizationRegistry is cleared. Then when afterComplection() is called on RegisteredSynchronization afterwards, any previously registered delegate synchronizations are gone already and thus do not get invoked. I believe I found a workaround for my case by registering my synchronization through JtaPlatform#registerSynchronization() (which registers it with the actual JTA transaction). My questions are: * Is this behaviour expected? * Is the work-around of doing the registration via JtaPlatform viable or are there any drawbacks which I'm not aware of? Thanks, --Gunnar [1] https://github.com/wildfly/wildfly/blob/master/jpa/src/main/java/org/jboss/as/jpa/transaction/TransactionUtil.java _______________________________________________ hibernate-dev mailing list hibernate-dev@lists.jboss.org https://lists.jboss.org/mailman/listinfo/hibernate-dev