Q:

When to close hibernate session?

I am using a dynamic web project. I open the session when the server starts. I use a single ton static class for this purpose and use the session everywhere around. 
But I am not sure when to close the session. Do you know where could it be handled? What is the best practice?

A:

There are two Object in Hibernate :
Short Answer : 
SessionFactory : Heavy Weight.
Session : light weight.

Long Answer : 
SessionFactory is responsible for creating connection with database and managing other stuff, so creating sessionFactory is time consuming task.
So I will say only one sessionFactory object should be created per Application, or in more better way one SeesionFactory per Database.
Now coming to your Session, it is light weight object, for each transaction you can create session object, when you are done with Transaction you can close session.

