Java – open and close hibernate sessions
This is how I get hibernate session and create a query
HSession.getSession().createQuery("query here").executeUpdate();
and
Critaria cr=HSession.getSession().createCritaria(..).. ;
Hssession is where my session factory is located, and the getsession () method returns a new session
(getSessionFactory().openSession();)
I wonder if
>After calling cr.list(); Is the conversation still alive? > If you are still alive, it is not good to obtain this standard or execute the query? And > create session as
Session s = HSession. getSession(); s.createCriteria …
Is the method of using the session and closing it with s.close()?
Solution
Yes, the session will exist until you close it You can perform multiple operations on a session, but only close () will close it
In your case, it appears that the session is controlled by hsession You need to view it to see if any transactions have been executed, how to manage sessions, and so on