I just got a connection between a Hibernate session and Connection. But now I have another question: how does hibernate sessionfactory manage the session? In the following code segment: the save () method of the DAO class:
Session session = sessionFactory.openSession();
Transaction tx=null;
tx=session.beginTransaction();
session.save(transientInstance);
session.flush();
tx.commit();
When we call sessionFactory.openSession(), it will create a new session connected to the current thread (via ThreadLocal), this session also connects to the JDBC connection, But, as you can see, we do not need to close the session (session.close ()) nor the connection. So, what is the life cycle of a Hibernate session, in what circumstances will it be closed? automatically?
source
share