[hibernate-dev] JTA synchronizations on WildFly
emmanuel at hibernate.org
Tue Mar 10 09:14:11 EDT 2015
Ah synchronization ordering, it never gets old :) Steve might remember better but I don’t think we ever managed to convice the tx team to offer guaranteed ordering.
Your workaround seems fine (if there is a JtaPlaform) but when we add more logic to your onRollback calls, we might want to offer access tot he Session to try compensating for example. In which case, we would be in trouble with the closed session. I don’t have a good idea.
I am a bit surprised WildFly closes the session but that might be per spec that the container manages these calls.
> On 10 Mar 2015, at 14:03, Gunnar Morling <gunnar at hibernate.org> wrote:
> 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
> 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 ) registers its own
> 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?
> hibernate-dev mailing list
> hibernate-dev at lists.jboss.org
More information about the hibernate-dev