Hello all,
I don't know whether this question is answered or not because I'm unable to find answer for my question. What is the good way to use hibernate. I'm actually talking about session opening and closing. Should we open a session at the start of application and close it when our application closes? OR We should open it every time we need to do some thing with database and then close the session again. What I observed is that opening and closing sessions takes lot of time and application slows down. But if I keep the session open the performance really increases. I dont know any of the risks involved. What would you say about this ?
lets say there are 4 classes A, B, C and a HibernateUtil. A, B and C call method
Code:
HibernateUtil.getInstance().getSession();
and HibernateUtil class returns the session object which is static in hibernate. If it is null it initializes and returns.
now whats are the side effects if i keep the connection open ?
or can some one please provide me a small project made using hibernate so that i can learn the best approach to use hibernate.