Solving classloading issue while adding pooling support using c3p0 in JPA with hibernate underneath
I added c3p0 for pooling in JPA, but encountered an exception
Unable to load class [org.hibernate.service.jdbc.connections.internal.C3P0ConnectionProvider]
My configuration looked like
<property name="hibernate.connection.provider_class" value="org.hibernate.connection.C3P0ConnectionProvider" /> <property name="hibernate.c3p0.max_size" value="10" /> <property name="hibernate.c3p0.min_size" value="0" /> <property name="hibernate.c3p0.acquire_increment" value="5" /> <property name="hibernate.c3p0.idle_test_period" value="60" /> <property name="hibernate.c3p0.max_statements" value="0" /> <property name="hibernate.c3p0.timeout" value="100" />
Details about these properties and other defined at link
Looking at log trace it’s not difficult to figure out that jar is not correct, so first change, upgrade to latest c3p0 artifact.
Previous
<dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-c3p0</artifactId> <version>3.6.10.Final</version> </dependency>
Latest
<dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-c3p0</artifactId> <version>4.1.9.Final</version> </dependency>
After changing this, it worked but printed an Warning
WARN - HHH000208: org.hibernate.connection.C3P0ConnectionProvider has been deprecated in favor of org.hibernate.service.jdbc.connections.internal.C3P0ConnectionProvider; that provider will be used instead.
This indicates that provider_class should be changed to remove the depricated class, so it should be
<property name="hibernate.connection.provider_class" value="org.hibernate.service.jdbc.connections.internal.C3P0ConnectionProvider" />
This cleanly integrated the c3p0 implementation.
Posted on January 21, 2013, in Hibernate, Java, MY SQL and tagged c3p0, Could not instantiate connection provider, hibernate, JPA. Bookmark the permalink. 2 Comments.
Nice article man, you saved my bacon.
Pingback: MySql connections autodrop after a certain hours « Thoughts on Software design and development