Joined: Wed Jan 28, 2009 9:57 am Posts: 16 Location: Leinfelden, Germany
|
|
Hello,
I am in the process of developing a persistence layer based on Hibernate. I want to use the ThreadLocal capability of Hibernate for obtaining a Session
I have the following properties set in the hibernate.cfg.xml
<property name="hibernate.current_session_context_class">thread</property>
<property name="hibernate.transaction.factory_class">org.hibernate.transaction.CMTTransactionFactory</property>
<property name="hibernate.transaction.manager_lookup_class">org.hibernate.transaction.WebSphereExtendedJTATransactionLookup</property>
<property name="hibernate.transaction.flush_before_completion">true</property>
<property name="hibernate.transaction.auto_close_session">true</property>
The SessionFactory.getCurrentSession() returns a session but when I try to perform an operation on this session, I get a HibernateException with the following message.
"get is not valid without active transaction"
I was under the impression that since I am using a datasource and a managed environment, the transaction would be associated with the Session.
Am I missing a config parameter or is the approach altogether wrong?
This error does not occur when I use SessionFactory.openSession()
Alternatively, I could implement ThreadLocal code myself and set a Session obtained by the SessionFactory.openSession().
Any help would be much appreciated.
|
|