Hi,
I am trying to complete the first tutorial of the book "Java Persistance with Hibarnate" but i get the following error when i do ant run:
Exception in thread "main" java.lang.ExceptionInInitializerError
[java] at persistence.HibernateUtil.<clinit>(Unknown Source)
[java] at hello.HelloWorld.main(Unknown Source)
[java] Caused by: java.lang.NoClassDefFoundError: com/mchange/v2/c3p0/DataSources
[java] at org.hibernate.connection.C3P0ConnectionProvider.configure(C3P0ConnectionProvider.java:154)
[java] at org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:124)
[java] at org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:56)
[java] at org.hibernate.cfg.SettingsFactory.createConnectionProvider(SettingsFactory.java:414)
[java] at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:62)
[java] at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2073)
[java] at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1298)
[java] ... 2 more
[java] Caused by: java.lang.ClassNotFoundException: com.mchange.v2.c3p0.DataSources
[java] at java.net.URLClassLoader$1.run(Unknown Source)
[java] at java.security.AccessController.doPrivileged(Native Method)
[java] at java.net.URLClassLoader.findClass(Unknown Source)
[java] at java.lang.ClassLoader.loadClass(Unknown Source)
[java] at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
[java] at java.lang.ClassLoader.loadClass(Unknown Source)
[java] at java.lang.ClassLoader.loadClassInternal(Unknown Source)
[java] ... 9 more
[java] Java Result: 1
**********************************************************
Hibernate version: 3.0
Mapping documents:
Code between sessionFactory.openSession() and session.close(): Session session = HibernateUtil.getSessionFactory().openSession(); Transaction tx = session.beginTransaction(); Message message = new Message("Hello World"); Long msgId = (Long) session.save(message); tx.commit(); session.close(); // Second unit of work Session newSession = HibernateUtil.getSessionFactory().openSession(); Transaction newTransaction = newSession.beginTransaction(); List messages = newSession.createQuery( "from Message m order by m.text asc").list(); System.out.println(messages.size() + " message(s) found:"); for (Iterator iter = messages.iterator(); iter.hasNext();) { Message loadedMsg = (Message) iter.next(); System.out.println(loadedMsg.getText()); } newTransaction.commit(); newSession.close();
Full stack trace of any exception that occurs: Exception in thread "main" java.lang.ExceptionInInitializerError [java] at persistence.HibernateUtil.<clinit>(Unknown Source) [java] at hello.HelloWorld.main(Unknown Source) [java] Caused by: java.lang.NoClassDefFoundError: com/mchange/v2/c3p0/DataSources [java] at org.hibernate.connection.C3P0ConnectionProvider.configure(C3P0ConnectionProvider.java:154) [java] at org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:124) [java] at org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:56) [java] at org.hibernate.cfg.SettingsFactory.createConnectionProvider(SettingsFactory.java:414) [java] at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:62) [java] at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2073) [java] at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1298) [java] ... 2 more [java] Caused by: java.lang.ClassNotFoundException: com.mchange.v2.c3p0.DataSources [java] at java.net.URLClassLoader$1.run(Unknown Source) [java] at java.security.AccessController.doPrivileged(Native Method) [java] at java.net.URLClassLoader.findClass(Unknown Source) [java] at java.lang.ClassLoader.loadClass(Unknown Source) [java] at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source) [java] at java.lang.ClassLoader.loadClass(Unknown Source) [java] at java.lang.ClassLoader.loadClassInternal(Unknown Source) [java] ... 9 more [java] Java Result: 1
Database used: hsqldb
My hibernate.cfg.xml file is as follows:
package hello;
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration SYSTEM
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class"> org.hsqldb.jdbcDriver </property>
<property name="hibernate.connection.url"> jdbc:hsqldb:hsql://localhost </property>
<property name="hibernate.connection.username"> sa </property>
<property name="connection.password"></property>
<property name="hibernate.dialect"> org.hibernate.dialect.HSQLDialect </property>
<!-- Use the C3P0 connection pool provider -->
<property name="hibernate.c3p0.min_size">5</property>
<property name="hibernate.c3p0.max_size">20</property>
<property name="hibernate.c3p0.timeout">300</property>
<property name="hibernate.c3p0.max_statements">50</property>
<property name="hibernate.c3p0.idle_test_period">3000</property>
<!-- Show and print nice SQL on stdout -->
<property name="show_sql">true</property>
<property name="format_sql">true</property>
<!-- List of XML mapping files -->
<mapping resource="hello/Message.hbm.xml" />
</session-factory>
</hibernate-configuration>
Any help appreciated,
Thanks in advance,
giannis
|