Code example for Session

Methods: closedoWork

0
 
  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);
  } 
}