Hi, I am using hibernate 3.2 and I try to implement the "session per request" paragdim with the org.hibernate.context.ThreadLocalSessionContext .
I don't understand as well the difference between openSession() and getCurrentSession() methods of the SessionFactory class.
I know that the session returned by openSession() is not attached to the current thread while the one return by getCurrentSession is. But the 2 session seems to be in different states. For example, the following code works fine :
Code:
org.hibernate.Session sessionHibernate = com.apis.b7afn.wda.mapping.util.HibernateUtil.getSessionFactory().openSession();
sessionHibernate.createQuery("from B7AFNWDATTypologie where valeur = 'typeAchat'").list();
out.println("ok");
and this one don't work :
Code:
org.hibernate.Session sessionHibernate = com.apis.b7afn.wda.mapping.util.HibernateUtil.getSessionFactory().getCurrentSession();
sessionHibernate.createQuery("from B7AFNWDATTypologie where valeur = 'typeAchat'").list();
out.println("ok");
In the second piece of code I have to open a transaction to run my query. This is not necessary in the first one.
How can I execute a query using the second way without opening a transaction?
Thanks for reply.
My apologies for my english.