Note: This bug is displayed in read-only format because the product is no longer active in Red Hat Bugzilla.

Bug 453179

Summary: Hibernate Session Context Configured Wrong
Product: [Retired] JBoss Customer Support Portal Reporter: John Sanda <jsanda>
Component: Web-GeneralAssignee: JBoss CSP Bug Watch List <csp-bugs-watch>
Status: CLOSED CURRENTRELEASE QA Contact:
Severity: medium Docs Contact:
Priority: medium    
Version: 1.3.9CC: fmerenda
Target Milestone: ---   
Target Release: ---   
Hardware: All   
OS: All   
Whiteboard:
Fixed In Version: MR8-CSP Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2009-01-30 17:37:41 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On:    
Bug Blocks: 453180, 463287    

Description John Sanda 2008-06-27 18:18:13 UTC
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:

Comment 1 John Sanda 2008-07-01 19:05:39 UTC
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.

Comment 2 John Sanda 2008-07-24 18:39:02 UTC
This bug has been fix in a branch at
https://svn.devel.redhat.com/repos/CSP/branches/developer-branches/jsanda/hibernate-testing.

Comment 3 John Sanda 2009-01-30 17:37:41 UTC
This was fixed and released in MR8. Hibernate is now configured to participate in JTA transactions.