Hibernate : Where exactly do we need to close the SessionFactory Object

hibernate, sessionfactory

Solution

I cannot think of any reason (offhand) why you would want to close the session factory while your application exists, so I wouldn't be too concerned about reclaiming the memory. I would just close it when your application is shutting down.

Problem

I am using Hibernate 3 version for my Application . While going through tutorials on Hibernate, I found out that, `SessionFactory` should be created only once for the application. So for this I have decided to use a static block inside a class and a static method to return this as shown. ``` public class SessionFactoryInitiliaztion { static { try { sessionFactory = new Configuration().configure().buildSessionFactory(); } catch (Exception x) { x.printStackTrace(); } } public static SessionFactory getSessionFactory() { return sessionFactory; } } ``` Where exactly do I need to close this `sessionFactory` object , so that it resales the memory ?

Original source

Related problems