Make delicious recipes!

Connection pooling in Hibernate

Hibernate has native connection pooling available which it does not recommend for use but still its good enough to appear in many commercial and large sized deployments.

One of the problems the native connection pool has is that it does not try to keep-alive the connections which are closed by the DB due to inactivity.
So, for example, if there is lesser load during the night and heavy during the morning time, then the connections lost during night have to be re-made and that adds to the already loaded system in the morning.

An easier alternative to the native hibernate connection pool is to use C3P0 library that augments the standard JDBC libraries by providing an excellent connection pool.
Hibernate just needs some property file bindings to make it switch to C3P0 pool.

To use C3P0, following steps are required:

1) Add C3P0 jar

2) Add following to hibernate.cfg.xml

3) Add a file

Like us on Facebook to remain in touch
with the latest in technology and tutorials!

Got a thought to share or found a
bug in the code?
We'd love to hear from you:

Email: (Your email is not shared with anybody)

Facebook comments:

Site Owner: Sachin Goyal