I’m looking into JTA-coordinated transactions with Hibernate and it seems like it’s not implemented.
In Hibernate 6.5.2, I’m looking at where a org.hibernate.internal.SessionImpl (subclass of org.hibernate.internal.AbstractSharedSessionContract) gets constructed. In the parent AbstractSharedSessionContract constructor, there is logic to determine which type of transaction coordinator to use…JTA vs. JDBC.
To determine this, the isTransactionCoordinatorShared(SessionCreationOptions options) is called. If options is an instance of the org.hibernate.internal.SharedSessionCreationOptions then the transaction coordinator will be JTA. Otherwise, it’ll be JDBC.
The only usage of SharedSessionCreationOptions I see in the Hibernate codebase is in the private inner class SessionImpl.SharedSessionBuilderImpl. The only place that class gets constructed is in the SessionImpl.sessionWithOptions() method. And that sessionWithOptions method is NEVER USED in the Hibernate codebase (beyond delegate wrappers calling it…which will never be populated with a SharedSessionBuilderImpl).
So it appears to me that lines 202-215 of AbstractSharedSessionContract in version 6.5.2 would NEVER be called, and JTA would never coordinate the transactions.
if(isTransactionCoordinatorShare) {
…
}
What am I not seeing, and how do I ensure that my Hibernate implementation can do the following?
Parent transaction in 1 thread which coordinates calls to 2 separate databases in 2 separate child threads running in parallel?