Hi
I am checking if it is possible to integrate Hibernate's JTA TransactionFactory to lookup/follow GemFire's transaction manager as JTA provider.
I am trying to execute a set of operations as described below as a part of function execution.
I want myregion.put & factory.getCurrentSession().update(...) to be part of same underlying JTA Transaction that is started by using GemFire as JTA Provider
try{ Context ctx = Cache.getJNDIContext(); UserTransaction tx = (UserTransaction)ctx.lookup("java:/UserTransaction"); tx.begin(); // Do some work factory.getCurrentSession().update(...); myregion.put(...); tx.commit();}catch (RuntimeException e) { tx.rollback(); throw e; // or display error message}
more details can be found here under Transaction Demarcation with JTA : https://community.jboss.org/wiki/SessionsAndTransactions
After tx.commit();, I do not see hibernate applying changes to database.
I have provided system property as below, as it is suggested in another thread, after which Hibernate is able to locate transaction in JNDI
System.setProperty(Context.INITIAL_CONTEXT_FACTORY, "com.gemstone.gemfire.internal.jndi.InitialContextFactoryImpl");
This is GemFire 6.6.3 and Hibernate has its own database connection pool.
There are no JNDI bindings declared in cache.xml
I had to add a GemFireTransactionManagerLookup class as below to be provided in hibernate's hibernate.transaction.manager_lookup_class element
import org.hibernate.HibernateException;
import org.hibernate.transaction.TransactionManagerLookup;
import javax.transaction.Transaction;
import javax.transaction.TransactionManager;
import java.util.Properties;
public class CGemFireTransactionManagerLookup implements TransactionManagerLookup {
@Override
public TransactionManager getTransactionManager(Properties properties) throws HibernateException {
return com.gemstone.gemfire.internal.jta.TransactionManagerImpl.getTransactionManager();
}
@Override
public String getUserTransactionName() {
return "java:/UserTransaction";
}
@Override
public Object getTransactionIdentifier(Transaction transaction) {
return transaction;
}
}
hibernate cfg settings
<property name="jta.UserTransaction">java:/UserTransaction</property>
<property name="hibernate.current_session_context_class">jta</property>
<property name="hibernate.transaction.factory_class">org.hibernate.transaction.JTATransactionFactory</property>
<property name="hibernate.transaction.manager_lookup_class">CGemFireTransactionManagerLookup</property>
Am I missing something here?
thanks