-->
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.  [ 6 posts ] 
Author Message
 Post subject: Hibernate Configuration
PostPosted: Mon Aug 17, 2009 8:22 am 
Newbie

Joined: Wed May 28, 2008 3:56 pm
Posts: 18
Hi,

I get the following exception when I try to setup Hibernate
java.lang.NoClassDefFoundError: org.hibernate.cfg.Configuration

I assume this is because it cannot find hibernate.cfg.xml.

I tried placing it in the root folder and even in the folder where HibernateUtil resides.

**********HibernateUtil**********
package persistance;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
public class HibernateUtil {
private static final SessionFactory sessionFactory;
static {
sessionFactory = new Configuration().configure().buildSessionFactory();
}
public static SessionFactory getSessionFactory() {
return sessionFactory;
}
}
*****************************

The project structure is
>PROJECT
>>BUSINESS
>>DAO
>>>src
>>>>persistance
>>>>>HibernateUtil
>>>hibernate.cfg.xml
>>PROJECT
>>deployment.xml
>>PROJECTWeb
>>>WebContent
>>>>WEB-INF
>>>>>lib
>>>>>>hibernate3.jar

Where did my configuration go wrong ?


Last edited by anotherjavauser on Mon Aug 17, 2009 8:32 am, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: Hibernate Configuration
PostPosted: Mon Aug 17, 2009 8:32 am 
Newbie

Joined: Wed Jun 03, 2009 3:22 pm
Posts: 3
Hey,
This is not because of the hibernate.cfg.xml file location, but the hibernate3.jar file. Please try to add this Jar file to your class path if you are working using text editors OR add it to the classpath in build Path Property in Eclipse.


Top
 Profile  
 
 Post subject: Re: Hibernate Configuration
PostPosted: Mon Aug 17, 2009 8:35 am 
Newbie

Joined: Wed May 28, 2008 3:56 pm
Posts: 18
Hey thanks for the quick response...

Well, it is in the lib folder so that would meet that it is also in the classpath. Do I need any other jars.

In the meanwhile, I'll try downloading the jar again.


Top
 Profile  
 
 Post subject: Re: Hibernate Configuration
PostPosted: Mon Aug 17, 2009 8:51 am 
Newbie

Joined: Wed Jun 03, 2009 3:22 pm
Posts: 3
Is that lib folder is added to your Build Path in Eclipse? because as you said, it is throwing ClassNotFoundException, at Configuration so, that Class is available in that Jar file only, so, your are missing at configuring that.
IF you are sure about the Jar file then, pic the hibernate.cfg.xml file from src/ folder and put it in persistance/ as HibnerateUtil exist there..And try..


Top
 Profile  
 
 Post subject: Re: Hibernate Configuration
PostPosted: Mon Aug 24, 2009 4:37 am 
Newbie

Joined: Wed May 28, 2008 3:56 pm
Posts: 18
Well, it has to be in the class path otherwise the imports.

[code]
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
[/code]

would have displayed a compilation error.

Also, I tried placed the hibernate.cfg.xml at all possible locations in the folder structure but it does not seem to work. Is it because something in my RAD7.0/struts 2.0 environment is preventing the configuration file from being picked up.


Top
 Profile  
 
 Post subject: Re: Hibernate Configuration
PostPosted: Mon Aug 24, 2009 4:57 am 
Newbie

Joined: Wed Jun 03, 2009 3:22 pm
Posts: 3
Hey,
Try this, if you think valid. There is a way we can run appl with out hibernate.cfg.xml, by callling addProperties(Properties p) object on configuration object, and adding Mapping resources using addResource("....hbm.xml") and try to execute your app. (refer Doc for further info.).
OR
give, full path of "hibernate.cfg.xml" as parameter to .configure() method, and try.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 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.