I am using Hibernate c3p0's Connection Pool
<property name="hibernate.c3p0.acquire_increment">1</property>
<property name="hibernate.c3p0.idle_test_period">100</property>
<property name="hibernate.c3p0.max_size">10</property>
<property name="hibernate.c3p0.max_statements">10</property>
<property name="hibernate.c3p0.min_size">10</property>
<property name="hibernate.c3p0.timeout">100</property>
<property name="hibernate.connection.provider_class">org.hibernate.connection.C3P0ConnectionProvider</property>
the dependency is defined in my pom.xml, and jar inside the library
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-c3p0</artifactId>
<version>4.3.6.Final</version>
</dependency>
The C3P0 connector gets picked up while starting my application:
INFO: HHH000130: Instantiating explicit connection provider: org.hibernate.connection.C3P0ConnectionProvider
Sep 10, 2014 7:39:39 PM org.hibernate.c3p0.internal.C3P0ConnectionProvider configure
INFO: HHH010002: C3P0 using driver: net.sourceforge.jtds.jdbc.Driver at URL: jdbc:jtds:sqlserver://localhost:1433/myDatabase
Sep 10, 2014 7:39:39 PM org.hibernate.c3p0.internal.C3P0ConnectionProvider configure
However, the code breaks at line 21:
3 | import org.hibernate.Session;
4 | import org.hibernate.SessionFactory;
5 | import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
6 | import org.hibernate.cfg.Configuration;
...
...
19 | Configuration configuration = new Configuration().configure();
20 | StandardServiceRegistryBuilder builder = new StandardServiceRegistryBuilder().applySettings(configuration.getProperties());
21 | SessionFactory sessionFactory = configuration.buildSessionFactory(builder.build());
And this is returned:
Exception in thread "main" java.lang.NoClassDefFoundError: com/mchange/v2/c3p0/DataSources
at org.hibernate.c3p0.internal.C3P0ConnectionProvider.configure(C3P0ConnectionProvider.java:203)
at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:111)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:234)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:206)
at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.buildJdbcConnectionAccess(JdbcServicesImpl.java:260)
at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:94)
at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:111)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:234)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:206)
at org.hibernate.cfg.Configuration.buildTypeRegistrations(Configuration.java:1885)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1843)
at com.boa.ecris.test.Main.main(Main.java:21)
Caused by: java.lang.ClassNotFoundException: com.mchange.v2.c3p0.DataSources
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
I've been searching online for quite sometime for deprecated jars, etc. But no luck yet. Any ideas?
Caused by: java.lang.ClassNotFoundException: com.mchange.v2.c3p0.DataSources
The Error Itself says that it is not able to Find the com.mchange.v2.c3p0.DataSources class from the jars which are added in your Maven Dependencies. The Exception is thrown at the time when you are configuring the Hibernate i.e., at LINE 19: Configuration configuration = new Configuration().configure();
Please add the c3p0-0.9.1.2.jar to the classpath or add the dependency in pom.xml from the link maven dependency. In my case, it worked!! hope it helps you too...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With