Yves Messi
Yves Messi

Reputation: 315

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?

Upvotes: 16

Views: 6116

Answers (1)

Boris the Spider
Boris the Spider

Reputation: 61178

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.

Upvotes: 22

Related Questions