title: Hibernate : Where exactly do we need to close the SessionFactory Object
body: <p>I am using Hibernate 3 version for my Application .</p>
  
  <p>While going through tutorials on Hibernate, I found out that, <code>SessionFactory</code> 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. </p>
  
  <pre><code>public class SessionFactoryInitiliaztion {
      static {
          try {
              sessionFactory = new Configuration().configure().buildSessionFactory();
          } catch (Exception x) {
              x.printStackTrace();
          }
      }
  
      public static SessionFactory getSessionFactory() {
          return sessionFactory;
      }
  }
  </code></pre>
  
  <p>Where exactly do I need to close this <code>sessionFactory</code> object , so that it resales the memory ?</p>