-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: JAVA Persistance with Hibernate Tutorial not working
PostPosted: Tue Aug 12, 2008 9:59 am 
Newbie

Joined: Tue Aug 12, 2008 2:32 am
Posts: 1
Location: Greece
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


Top
 Profile  
 
 Post subject: com/mchange/v2/c3p0/DataSources ClassNotFoundException
PostPosted: Tue Aug 12, 2008 11:09 am 
Newbie

Joined: Thu Mar 15, 2007 1:22 am
Posts: 11
This usually means that the DataSouces.class is NOT in your classpath. The issue seems to be that either there is a JAR not in your classpath with this class or the class is not in your classpath. Are you using ant or some build system? If so, check your classpath carefully as the ANT classpath is not used for your applications classpath. I would have it print out your classpath in your build tool if your using one. Otherwise echo $CLASSPATH on a *nix box or echo %CLASSPATH% on windows. This should tell you what is in your classpath, if you dont see your jar file containing this class or your CLASS basedir then it is NOT on your classpath. Fix that and re-run.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Nov 30, 2008 6:52 am 
Newbie

Joined: Sun Nov 30, 2008 4:49 am
Posts: 2
I am using Tomcat 6 (apache-tomcat-6.0.18)
Encountered the same issue.
I placed c3p0-0.9.1.jar in $CATALINA_HOME/endorsed directory
This issue was gone.


Phoneynk


Top
 Profile  
 
 Post subject:
PostPosted: Sun Nov 30, 2008 7:34 am 
Newbie

Joined: Sun Nov 30, 2008 6:23 am
Posts: 2
Caused by: java.lang.ClassNotFoundException: com.mchange.v2.c3p0.DataSources


the verbose error info is not always horrible.be careful,may be you can catch the bug yourself .

_________________
Email:devliu1986@gmail.com


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.