Description of problem: We have the following in our hibernate.cfg.xml: <property name="hibernate.current_session_context_class">thread</property> <property name="transaction.factory_class">org.hibernate.transaction.JTATransactionFactory</property> <property name="transaction.manager_lookup_class">org.hibernate.transaction.JBossTransactionManagerLookup</property> We are telling Hibernate that we are using JTA, but we are using a thread local session. We should be using a JTA session context (http://www.hibernate.org/hib_docs/v3/api/org/hibernate/context/JTASessionContext.html). It is the JTA session context which allows hibernate to participate in JTA transactions without explicit use of the JTA UserTransaction API. Version-Release number of selected component (if applicable): How reproducible: Steps to Reproduce: 1. 2. 3. Actual results: Expected results: Additional info:
Changing the configuration to include, <property name="hibernate.current_session_context_class">thread</property> results in the following exception at start up: java.lang.ExceptionInInitializerError at com.jboss.jbossnetwork.ui.listeners.StartupListener.contextInitialized(StartupListener.java:28) at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3763) . . . Caused by: org.hibernate.HibernateException: Unable to locate current JTA transaction at org.hibernate.context.JTASessionContext.currentSession(JTASessionContext.java:61) at org.hibernate.impl.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:542) at com.jboss.jbossnetwork.dao.GenericHibernateDAO.getSession(GenericHibernateDAO.java:56) at com.jboss.jbossnetwork.dao.GenericHibernateDAO.findByCriteria(GenericHibernateDAO.java:335) at com.jboss.jbossnetwork.dao.GenericHibernateDAO.getAll(GenericHibernateDAO.java:199) at com.jboss.jbossnetwork.util.config.Config.<clinit>(Config.java:22) This is because Hibernate is trying to join a JTA transaction, but one has not been started. The code where the exception originates is not part of an EJB method invocation, hence the exception. We need to either refactor that code into an EJB method call so the container handles the transaction for us, or we need to explicitly create the transaction.
This bug has been fix in a branch at https://svn.devel.redhat.com/repos/CSP/branches/developer-branches/jsanda/hibernate-testing.
This was fixed and released in MR8. Hibernate is now configured to participate in JTA transactions.