Bug 453179 - Hibernate Session Context Configured Wrong
Summary: Hibernate Session Context Configured Wrong
Keywords:
Status: CLOSED CURRENTRELEASE
Alias: None
Product: JBoss Customer Support Portal
Classification: Retired
Component: Web-General
Version: 1.3.9
Hardware: All
OS: All
medium
medium
Target Milestone: ---
: ---
Assignee: JBoss CSP Bug Watch List
QA Contact:
URL:
Whiteboard:
Depends On:
Blocks: 453180 463287
TreeView+ depends on / blocked
 
Reported: 2008-06-27 18:18 UTC by John Sanda
Modified: 2009-02-05 21:13 UTC (History)
1 user (show)

Fixed In Version: MR8-CSP
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2009-01-30 17:37:41 UTC
Type: ---
Embargoed:


Attachments (Terms of Use)

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.


Note You need to log in before you can comment on or make changes to this bug.