Code example for SessionFactory

Methods: openSession

0
  protected final HibernateTemplate hibernateTemplate;
 
  static { 
    //turn off foreign keys for testing 
    sessionFactory = new Configuration().configure().buildSessionFactory();
    Session session = sessionFactory.openSession();
    session.doWork(new Work() {
      @Override 
      public void execute(Connection connection) throws SQLException {
        // http://stackoverflow.com/questions/5174374/tests-throw-exception-saying-user-lacks-privilege-or-object-not-found-referenti 
        connection.createStatement().execute("SET DATABASE REFERENTIAL INTEGRITY FALSE;");
      } 
    }); 
    session.close();
  } 
 
  public BaseHibernateTest() { 
    this.hibernateTemplate = new HibernateTemplate(sessionFactory);
  } 
}