I am confused about the hibernate session and connection pool, are they the same thing?
The default connection pool in hibernate is c3p0 named after the star wars character. But hibernate supports also proxool and used to also advertise apache dbcp. For a while DBCP was dormant and fell out of grace. C3P0 is actually used in production in many projects.
Providing a connection pool for an application that uses Hibernate is pretty easy, as a matter of fact Hibernate supports a variety of connection pooling mechanisms. If you are using an application server such as WildFly, you may wish to use the built-in pool (typically a connection is obtaining using JNDI).
SessionFactory objects are one per application and Session objects are one per client. SessionFactory is to create and manage Sessions . Session is to provide a CRUD interface for mapped classes, and also access to the more versatile Criteria API .
Each connection in the connection pool has its own session pool. This means that there can be 10 session pools that can have a maximum of 10 sessions each. Each session represents a TCP/IP connection to the queue manager. With the settings mentioned here, there can be a maximum of 100 TCP/IP connections.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With