Problem
If you are using c3p0 connection pool for hibernate, then you probably have
on the hibernate.cfg.xml file the following configuration:
<!-- c3p0 connection pool (use the built-in) -->
<property name="connection.pool_size">c3p0</property>
<property name="c3p0.min_size">5</property>
<property name="c3p0.max_size">20</property>
<property name="c3p0.timeout">1800</property>
<property name="c3p0.max_statements">50</property>
When you run the application, it throws an exception like below:
21:03:25,016 INFO C3P0ConnectionProvider:82 - Connection properties: {user=root, password=****}
21:03:25,016 INFO C3P0ConnectionProvider:85 - autocommit mode: false
21:03:25,023 WARN C3P0ConnectionProvider:210 - Both hibernate-style property 'hibernate.c3p0.max_size' and c3p0-style property 'c3p0.max_size' have
been set in hibernate.properties.
Hibernate-style property 'hibernate.c3p0.max_size' will be used and c3p0-style property 'c3p0.max_size' will be ignored!
21:03:25,023 WARN C3P0ConnectionProvider:210 - Both hibernate-style property 'hibernate.c3p0.min_size' and c3p0-style property 'c3p0.min_size' have
been set in hibernate.properties.
Hibernate-style property 'hibernate.c3p0.min_size' will be used and c3p0-style property 'c3p0.min_size' will be ignored!
21:03:25,024 WARN C3P0ConnectionProvider:210 - Both hibernate-style property 'hibernate.c3p0.timeout' and c3p0-style property 'c3p0.timeout' have
been set in hibernate.properties.
Hibernate-style property 'hibernate.c3p0.timeout' will be used and c3p0-style property 'c3p0.timeout' will be ignored!
21:03:25,024 WARN C3P0ConnectionProvider:210 - Both hibernate-style property 'hibernate.c3p0.max_statements' and c3p0-style property
'c3p0.max_statements' have been set in hibernate.properties.Hibernate-style property 'hibernate.c3p0.max_statements' will be used and c3p0-style property 'c3p0.max_statements' will be ignored!
Initial SessionFactory creation failed.java.lang.NoClassDefFoundError: com/mchange/v2/c3p0/DataSources
Exception in thread "main" java.lang.ExceptionInInitializerError
at ipg.model.persistence.hbn.HbnDaoFactory.<clinit>(HbnDaoFactory.java:43)
at test.db.AdminVO_test.showList(AdminVO_test.java:120)
at test.db.AdminVO_test.main(AdminVO_test.java:46)
Caused by: java.lang.NoClassDefFoundError: com/mchange/v2/c3p0/DataSources
at org.hibernate.connection.C3P0ConnectionProvider.configure(C3P0ConnectionProvider.java:154)
at org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:124)
at org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:56)
at org.hibernate.cfg.SettingsFactory.createConnectionProvider(SettingsFactory.java:414)
at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:62)
at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2073)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1298)
at ipg.model.persistence.hbn.HbnDaoFactory.<clinit>(HbnDaoFactory.java:39)
... 2 more
Caused by: java.lang.ClassNotFoundException: com.mchange.v2.c3p0.DataSources
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
... 10 more
If you are using c3p0 connection pool for hibernate, then you probably have
on the hibernate.cfg.xml file the following configuration:
<!-- c3p0 connection pool (use the built-in) -->
<property name="connection.pool_size">c3p0</property>
<property name="c3p0.min_size">5</property>
<property name="c3p0.max_size">20</property>
<property name="c3p0.timeout">1800</property>
<property name="c3p0.max_statements">50</property>
When you run the application, it throws an exception like below:
21:03:25,016 INFO C3P0ConnectionProvider:82 - Connection properties: {user=root, password=****}
21:03:25,016 INFO C3P0ConnectionProvider:85 - autocommit mode: false
21:03:25,023 WARN C3P0ConnectionProvider:210 - Both hibernate-style property 'hibernate.c3p0.max_size' and c3p0-style property 'c3p0.max_size' have
been set in hibernate.properties.
Hibernate-style property 'hibernate.c3p0.max_size' will be used and c3p0-style property 'c3p0.max_size' will be ignored!
21:03:25,023 WARN C3P0ConnectionProvider:210 - Both hibernate-style property 'hibernate.c3p0.min_size' and c3p0-style property 'c3p0.min_size' have
been set in hibernate.properties.
Hibernate-style property 'hibernate.c3p0.min_size' will be used and c3p0-style property 'c3p0.min_size' will be ignored!
21:03:25,024 WARN C3P0ConnectionProvider:210 - Both hibernate-style property 'hibernate.c3p0.timeout' and c3p0-style property 'c3p0.timeout' have
been set in hibernate.properties.
Hibernate-style property 'hibernate.c3p0.timeout' will be used and c3p0-style property 'c3p0.timeout' will be ignored!
21:03:25,024 WARN C3P0ConnectionProvider:210 - Both hibernate-style property 'hibernate.c3p0.max_statements' and c3p0-style property
'c3p0.max_statements' have been set in hibernate.properties.Hibernate-style property 'hibernate.c3p0.max_statements' will be used and c3p0-style property 'c3p0.max_statements' will be ignored!
Initial SessionFactory creation failed.java.lang.NoClassDefFoundError: com/mchange/v2/c3p0/DataSources
Exception in thread "main" java.lang.ExceptionInInitializerError
at ipg.model.persistence.hbn.HbnDaoFactory.<clinit>(HbnDaoFactory.java:43)
at test.db.AdminVO_test.showList(AdminVO_test.java:120)
at test.db.AdminVO_test.main(AdminVO_test.java:46)
Caused by: java.lang.NoClassDefFoundError: com/mchange/v2/c3p0/DataSources
at org.hibernate.connection.C3P0ConnectionProvider.configure(C3P0ConnectionProvider.java:154)
at org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:124)
at org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:56)
at org.hibernate.cfg.SettingsFactory.createConnectionProvider(SettingsFactory.java:414)
at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:62)
at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2073)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1298)
at ipg.model.persistence.hbn.HbnDaoFactory.<clinit>(HbnDaoFactory.java:39)
... 2 more
Caused by: java.lang.ClassNotFoundException: com.mchange.v2.c3p0.DataSources
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
... 10 more
Solution
Missing the c3p0 jar files on the project's build path.
Download the jar file, for instance:
c3p0-0.9.1.2.jar
My application runs but when I try to use the HQL editor with eclipse I get:
ReplyDeleteProblems while creating sessionfactory
java.lang.NoClassDefFoundError:com/mchange/v2/c3P0/DataSources
The jar is present, the application runs, but I can't test HQL queries in the eclipse HQL editor.
Anyone else having this issue?
Running
Hibernate core 3.6.10
c3p0 0.9.1.2
hibernate-c3p0-3.6.10