In order to integrate JBossCache 3 into our app stack, I created a simple JTA impl that delegates work to underlying org.hibernate.JDBCTransaction. However, I am running into a problem with Isolater.JtaDelegate (to which org.hibernate.id.TableHiLoGenerator delegates work) because JtaDelegate does NOT use TransactionFactory in delegateWork() method.
When Session.beginTransaction() is called, Session delegates to JDBCContext which delegates creation of transaction to TransactionFactory:
Code:
public Transaction getTransaction() throws HibernateException {
if (hibernateTransaction==null) {
hibernateTransaction = owner.getFactory().getSettings()
.getTransactionFactory()
.createTransaction( this, owner );
}
return hibernateTransaction;
}
In my case I created a new TransactionFactory impl that:
-creates a JDBCTransaction
-passes it to our JTA TransactionManager impl which wraps it into a javax.transaction.Transaction
However, Isolater.JtaDelegate.delegateWork does not use Hibernate Transaction API (bypassing TransactionFactory.createTransaction) but instead does this:
Code:
TransactionManager transactionManager = session.getFactory().getTransactionManager();
//later
transactionManager.begin();
Should this be used instead?Code:
org.hibernate.Transaction tx = session.getFactory().getSettings().getTransactionFactory().createTransaction(session.getJDBCContext(), this);
tx.begin();
This way seems like Isolater wouldn't have to care whether JTA is being used or not...
I realize that strictly speaking a JTA implementation should create and start a transaction with TransactionManager.begin() call. However, I rely on TransactionFactory.createTransaction to run because I need method args of createTransaction(JDBCContext jdbcContext, Context transactionContext) to create a nested JDBCTransaction.