This is how I get a Hibernate Session and create query.
HSession.getSession().createQuery("query here").executeUpdate();
AND
Critaria cr=HSession.getSession().createCritaria(..).. ;
HSession is where my Session factory is located and getSession() method returns a new session
(getSessionFactory().openSession();)
I want to know whether
- After calling
cr.list();Is the session is still alive? - If alive, getting this criteria or executing a query way is not good? and
-
Creating a Session as
Session s=HSession.getSession();
s.createCriteria…Is the way to use the session and close it using
s.close();?
Yes, the session will be alive until you close it. You can perform multiple operations against a session, but only
close()will close it.In your case, it looks like the sessions are controlled by whatever
HSessionis. You’ll need to look at that to see if any transactions are performed, how the sessions are managed, etc.