Wednesday, August 26, 2009

Configuring Hibernate 3 with c3p0

Thought I'd share a little tip that doesn't (currently) appear in the documentation for configuring c3p0 connection pooling with Hibernate 3.

Apart from setting the properties below (which are documented):
<!-- configuration pool via c3p0-->
<property name="c3p0.acquire_increment">1</property>
<property name="c3p0.idle_test_period">100</property> <!-- seconds -->
<property name="c3p0.max_size">100</property>
<property name="c3p0.max_statements">0</property>
<property name="c3p0.min_size">10</property>
<property name="c3p0.timeout">100</property> <!-- seconds -->

You must also set the following (un-documented) property:
<property name="hibernate.connection.provider_class">org.hibernate.connection.C3P0ConnectionProvider</property>

If you do not set the provider_class property hibernate will continue to us the built-in connection pool!