Answer the question
In order to leave comments, you need to log in
How to close session in hibernate correctly?
I'm learning Hibernate, and I can't understand why I have to stop the main manually!!!??? I closed the session, the sessionFactory also closed, but the program does not stop, help me figure it out.
Postgresql database
Idea full environment
According to the hibenate logs, it can be seen that it works correctly, this is the latest hibernate output log
мар 16, 2018 3:51:54 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl stop
INFO: HHH10001008: Cleaning up connection pool [jdbc:postgresql://localhost:5432/testproj]
Process finished with exit code 130 (interrupted by signal 2: SIGINT)
SessionFactory sessionFactory =
HibernateUtil.buildSessionFactory();
Session session = sessionFactory.openSession();
try {
session.beginTransaction();
for(int i = 0; i < 5; i ++) {
UserEntity entity = new UserEntity();
entity.setFname("Alex");
entity.setNname("uuuuu" + i);
entity.setLname("Pon");
entity.setPassword("qwe");
entity.setPasswordTwo("qwe");
entity.setRole("admin");
session.save(entity);
}
session.beginTransaction().commit();
}catch (Exception e){
session.beginTransaction().rollback();
}finally {
System.out.println("before");
session.close();
sessionFactory.close();
HibernateUtil.shutdown();//тут в этом классе закрывается сессион фактори, но я и ясно уже добавил.
System.out.println("after");
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question