Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference and relationship between the hibernate session and connection pool?

I am confused about the hibernate session and connection pool, are they the same thing?

like image 224
Yves Messi Avatar asked Mar 24 '13 17:03

Yves Messi


People also ask

What is the connection pool in Hibernate?

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.

Why do we need connection pool in Hibernate?

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).

What is the difference between Session and SessionFactory in Hibernate?

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 .

What is connection pool Session?

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.


1 Answers

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. Connections 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.

like image 154
Boris the Spider Avatar answered Sep 29 '22 13:09

Boris the Spider