I am using Hibernate 3.2 with Tomcat. I am having the JTATransactionManager since Tomcat does not have one, and the transaction.manager_lookup_class is the org.hibernate.transaction.JOTMTransactionManagerLookup.
I read that if I use Hibernate 3.x (a more advanced than 3.0) the sessionFactory.getCurrentSession() is all I need for session.
But I have
a null pointer exception.The method works only if I use the openSession().
Here is my code in my UserDao:
Code:
session = HibernateUtil.getSessionFactory().getCurrentSession();
Context ctx = new InitialContext();
tx = (UserTransaction)ctx.lookup("java:comp/env/UserTransaction");
tx.begin();
session.get(User.class, new Long(1));
tx.commit();
session.close()
Is the order of Session and transaction correct?
If I open first the transaction and then get session I have :
Code:
org.hibernate.HibernateException: get is not valid without active transaction
Any suggestions?