P
P
P_Alexander2018-03-16 16:59:47
Java
P_Alexander, 2018-03-16 16:59:47

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]

If I slow down the program with the STOP button, then the output is
Process finished with exit code 130 (interrupted by signal 2: SIGINT)

Having rummaged through Google, I found out that this is connected with the bush shell, whether it’s true or not, I don’t know, and the solution, as it were, too.
Please explain what it is and how to solve it?
just in case code
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

1 answer(s)
A
alfss, 2018-05-07
@alfss

I don't know if this is possible, but here is the answer: https://stackoverflow.com/questions/21645516/progr...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question