I am confused about the hibernate session and connection pool, are they the same thing?
1 Answer
Hibernate is an ORM, it is a layer between a SQL database and your POJOs.
A connection pool provides a way to store and reuse java.sql.Connection
instances for speed and robustness.
A hibernate Session
is a wrapper around a Connection
in order to allow you to save your POJOs without directly writing the SQL.
So a hibernate Session
is a wrapper around a Connection
. Connection
s are held in a connection pool.
When you call SessionFactory.openSession
hibernate first takes a Connection
from the supplied connection pool. It then creates a Session
around that Connection
and returns it.
-
-
@user_mda you should not be thinking about connections when using JPA. It can do what it wants under the hood. Practically speaking it would probably call
close
on theConnection
, yes, but that's an implementation detail. Aug 10, 2015 at 20:04 -
what is the difference between session.close() and session.flush()?– user_mdaAug 11, 2015 at 15:34
-
but HibernateUtil.getNewSession() does not create a new connection? May 24, 2022 at 14:50