| Some related discussion occurred on Narayana forum thread Design Discussion: Changing the reaper to use setRollbackOnly() instead of rollback() and also on Requirement for an observer SPI for tracking thread-to-transaction association changes. In the first link on "setRollbackOnly", most of the relevant content is more toward the last few pages. The second link on "tracking thread-to-transaction association changes" is the most relevant for what we should instead be doing in Hibernate. The idea presented in the second link, is that when the transaction manager calls Synchronization.afterCompletion(int), it is only safe to perform the desired Hibernate afterCompletion action, only if the application thread has already been disassociated from the same JTA transaction. A code example that performs this check is at https://github.com/wildfly/wildfly/blob/master/jpa/subsystem/src/main/java/org/jboss/as/jpa/transaction/TransactionUtil.java#L146. Note that the same class instance is implementing Synchronization + org.jboss.tm.listener.TransactionListener. The TransactionListener informs WildFly of when the application thread is associated/disassociated with the JTA transaction. |