-->
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.  [ 13 posts ] 
Author Message
 Post subject: Pb with hibernate.cfg.xml not in root of classpath
PostPosted: Tue Nov 25, 2003 11:18 am 
Beginner
Beginner

Joined: Thu Nov 13, 2003 9:27 am
Posts: 26
Location: France
Hi all,

I've a problem with my hibernate.cfg.xml. I put it in dir1\dir2\resources\hibernate.cfg.xml and my root of classpath is \dir1.

I have this exception :

Code:
15:54:51,093  INFO Configuration:794 - Configuration resource: \dir1\dir2\resources\hibernate.cfg.xml

15:54:51,093  WARN Configuration:798 - \dir1\dir2\resources\hibernate.cfg.xml not found

15:54:51,109 ERROR SessionHibernate:54 - Erreur hibernate \dir1\dir2\resources\hibernate.cfg.xml not found


Here is my java code :

Code:
chemin = "/dir1/dir2/resources/hibernate.cfg.xml" ;
            chemin = chemin.replace('/',File.separatorChar) ;
            sessionFactory = new Configuration().configure(chemin).buildSessionFactory() ;


Can u see where I did wrong ? Or should I put my configuration file only in \dir1 ?

Thx in advance for ur help :)


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 25, 2003 11:29 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
chemin = "/dir2/resources/hibernate.cfg.xml" ;

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 25, 2003 11:41 am 
Beginner
Beginner

Joined: Thu Nov 13, 2003 9:27 am
Posts: 26
Location: France
No sorry, it doesn't work either...


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 25, 2003 11:45 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Hum remove
Code:
chemin = chemin.replace('/',File.separatorChar) ;

Hibernate will look at you CP, not physical file system.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 25, 2003 12:38 pm 
Beginner
Beginner

Joined: Thu Nov 13, 2003 9:27 am
Posts: 26
Location: France
nop nop nop *ouinn* it does not work either.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 25, 2003 12:49 pm 
Beginner
Beginner

Joined: Thu Nov 13, 2003 9:27 am
Posts: 26
Location: France
By the way, I use Hibernate 2.1 b


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 25, 2003 1:12 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Since hibernate will do a
Code:
Environment.class.getResourceAsStream(chemin);

then the file is not in the classpath associated with the classloader that load Hibernate.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 25, 2003 1:27 pm 
Beginner
Beginner

Joined: Thu Nov 13, 2003 9:27 am
Posts: 26
Location: France
I'm not sure I understand well. Does that mean that I MUST put it in the root classpath ?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 25, 2003 2:13 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Hum, actually you're right I can't remenber correct syntax out of root cp.

/myfile.xml will load the file in the cp root. I don't know otherwise.

_________________
Emmanuel


Top
 Profile  
 
 Post subject: Load it yourself...
PostPosted: Tue Nov 25, 2003 4:02 pm 
Senior
Senior

Joined: Sun Aug 31, 2003 3:14 pm
Posts: 151
Location: Earth (at the moment)
Code:
URL configFileURL = Class.class.getResource(YOUR_PATH);
Configuration configuration = new Configuration().configure(configFileURL);


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 26, 2003 6:41 am 
Beginner
Beginner

Joined: Thu Nov 13, 2003 9:27 am
Posts: 26
Location: France
When I do as u said, I have this different exception :


Code:
java.lang.NullPointerException
   at net.sf.hibernate.cfg.Configuration.configure(Configuration.java:837)
   at dir1.dir2.SessionHibernate.initHibernate(SessionHibernate.java:50)
   at dir1.dir2.AdhesionServiceImpl.myMethod(myMethod.java:115)
   at TestCnxDB.main(TestCnxDB.java:34)


Got an idea ?


Top
 Profile  
 
 Post subject: Check for NULL...
PostPosted: Wed Nov 26, 2003 1:56 pm 
Senior
Senior

Joined: Sun Aug 31, 2003 3:14 pm
Posts: 151
Location: Earth (at the moment)
Check if the configFileURL is NULL.
If it is, the class loader couldn't load the path specified. I would guess that this is most likely because of an error in your path or because you didn't copy the xml file from your src directory to your build directory (or where ever you are trying to run the classes from).

Based on your previous messages I would guess that the call should look like this:
Code:
URL configFileURL = Class.class.getResource("/dir1/dir2/resources/hibernate.cfg.xml");

I'm guessing your path is something like "/com/yourcompany/resources/hibernate.cfg.xml" correct?

Are you deploying to some server such as with a WAR file or doing some other kind of file copy where the xml config file might not have been copied to the classes directory?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 26, 2003 2:39 pm 
Newbie

Joined: Thu Nov 13, 2003 1:14 pm
Posts: 18
Location: Leinfelden-Echterdingen, Germany
in my code I have something like

Code:
Configuration cfg = (new Configuration()).configure(new File("etc/Hibernate.cfg.xml"));


It works very well. Btw, the etc-dir is in the root of the classpath (the directory I start my app from).

Regards,

Peter


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