-->
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.  [ 11 posts ] 
Author Message
 Post subject: hibernate.cfg.xml not found
PostPosted: Mon Feb 21, 2005 5:46 pm 
Newbie

Joined: Mon Feb 21, 2005 5:42 pm
Posts: 10
Hi!!
I'm new with hibernate. I'm trying to make an example with mysql and hibernate using JBuiderX
I defined a class Singleton with the following code

public class Singleton {

private SessionFactory sessionFactory;

public Singleton() {
try {
System.out.println("Initializing Hibernate");
sessionFactory = new Configuration().configure().buildSessionFactory();
System.out.println("Finished Initializing Hibernate");
} catch (HibernateException e) {
e.printStackTrace();
}
}

public static void main(String[] args) {
Singleton instance = new Singleton();
System.exit(0);
}

}

as the hibernate documentation say. But when I run the Singleton to see if I can connect, I obtain the following error

log4j:WARN No appenders could be found for logger (net.sf.hibernate.cfg.Environment).

log4j:WARN Please initialize the log4j system properly.

net.sf.hibernate.HibernateException: /hibernate.cfg.xml not found
at net.sf.hibernate.cfg.Configuration.getConfigurationInputStream(Configuration.java:872)
at net.sf.hibernate.cfg.Configuration.configure(Configuration.java:896)
at net.sf.hibernate.cfg.Configuration.configure(Configuration.java:883)
at com.tutorial.hibernate.db.Singleton.<init>(Singleton.java:23)
at com.tutorial.hibernate.db.Singleton.main(Singleton.java:31)

The hibernate.cfg.xml is in the src directory
Anybody can help me!!!
REgards

Naty


Top
 Profile  
 
 Post subject: Re: hibernate.cfg.xml not found
PostPosted: Mon Feb 21, 2005 7:34 pm 
Regular
Regular

Joined: Thu Dec 18, 2003 2:14 am
Posts: 103
Location: Brooklyn, NY
naty wrote:
The hibernate.cfg.xml is in the src directory

Needs to be in the classpath, not the source path.


Top
 Profile  
 
 Post subject: Re: hibernate.cfg.xml not found
PostPosted: Tue Feb 22, 2005 9:53 am 
Newbie

Joined: Mon Feb 21, 2005 5:42 pm
Posts: 10
Thank you!
I put the hibernate.cfg.xml in a lib directory where I have .jar 's files and still the problem. lib directory is on the class file because there I have my mysql.jar driver.
Any other Idea?
Only work's if I put hibernate.cfg.xml on the class directory but when I rebuilt the project I lost the .xml file.
Regards

Naty


Top
 Profile  
 
 Post subject: hibernate.cfg.xml not found
PostPosted: Tue Feb 22, 2005 10:04 am 
Newbie

Joined: Mon Feb 21, 2005 5:42 pm
Posts: 10
Sorry in the last message I mean classes directory not class directory


Top
 Profile  
 
 Post subject: Re: hibernate.cfg.xml not found
PostPosted: Tue Feb 22, 2005 10:10 am 
Regular
Regular

Joined: Thu Dec 18, 2003 2:14 am
Posts: 103
Location: Brooklyn, NY
naty wrote:
Only work's if I put hibernate.cfg.xml on the class directory but when I rebuilt the project I lost the .xml file.

This is where it goes, in "classes". Adjust your build script to copy it from sources when you do a build.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 22, 2005 10:56 am 
Expert
Expert

Joined: Fri Nov 07, 2003 4:24 am
Posts: 315
Location: Cape Town, South Africa
try

Code:
sessionFactory = new Configuration().configure("/hibernate.cfg.xml").buildSessionFactory();


.. and let us know what the results are (The file must be in the root of the classpath)

Code:
sessionFactory = new Configuration().configure().buildSessionFactory();

should produce the same result - but there may be an issue here...


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 22, 2005 11:34 am 
Regular
Regular

Joined: Thu Dec 18, 2003 2:14 am
Posts: 103
Location: Brooklyn, NY
drj wrote:
but there may be an issue here...

I doubt there is an issue. He says it works when he puts the config in the root of "classes", where it belongs. The only issue is that this config gets overwritten by his compilation. He needs to edit his build script to copy the config from the source root, nothing more. Mappings needs to get copied too. This is built-in with Eclipse, and trivial with ant.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 22, 2005 2:26 pm 
Newbie

Joined: Thu Feb 17, 2005 10:26 am
Posts: 3
hi

i am a new user to hibernate and i am using hibernate 2.16 along with hsqldb 1.7 with netbean 4.0 as ide with jdk1.5.

whenever i run hibernate through netbeans, i am getting the following error.
i get the same error when i run through the command prompt.
i need to know whether i have to set classpath differently for hibernate.cfg.xml. i am putting this file in the source directory under the development directory.
even the corresponding jar created through compiling with netbeans records this file location, but does not detect it when run.

run:

15:48:45,905 INFO Environment:469 - Hibernate 2.1.6
15:48:45,921 INFO Environment:498 - hibernate.properties not found
15:48:45,921 INFO Environment:529 - using CGLIB reflection optimizer
15:48:45,936 INFO Configuration:895 - configuring from resource: /hibernate.cfg.xml
15:48:45,936 INFO Configuration:867 - Configuration resource: /hibernate.cfg.xml
15:48:45,936 WARN Configuration:871 - /hibernate.cfg.xml not found
Exception in thread "main" net.sf.hibernate.HibernateException: /hibernate.cfg.xml not found
at net.sf.hibernate.cfg.Configuration.getConfigurationInputStream(Configuration.java:872)
at net.sf.hibernate.cfg.Configuration.configure(Configuration.java:896)
at net.sf.hibernate.cfg.Configuration.configure(Configuration.java:883)
at test.hiber.InsertProduct.main(InsertProduct.java:27)
Java Result: 1
BUILD SUCCESSFUL (total time: 0 seconds)


The cause of error occurs at the line where we initialise transaction.
the other mechanism of using hibernate.properties file does not work as it is also not getting detected.


can anyone help me out with this trouble. i have been struck for over 4 days with this.

karthik.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 22, 2005 2:28 pm 
Regular
Regular

Joined: Thu Dec 18, 2003 2:14 am
Posts: 103
Location: Brooklyn, NY
Does the conifg file exist in the classes directory? I think you have the same compiling issue as the other guy: make sure it copies xml files when it compiles. Read the docs for your IDE to learn how to do this.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 22, 2005 3:08 pm 
Newbie

Joined: Thu Feb 17, 2005 10:26 am
Posts: 3
hi mgreer,

the ide copies all the xml files, properties files into the classes directory.
even the compiled jar has got the file.
but during run time it shows the above exception

as regards classpath. can u elaborate more on that. because i am confused with environment variable.

please update me on this

...karthik


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 28, 2005 11:20 am 
Newbie

Joined: Mon Feb 21, 2005 5:42 pm
Posts: 10
Hi everybody!!!
Thanks a lot for help!
I finally resolve the problem enabling .xml extension in the configuration of JBuilder. Now in the src I can see the .java and the .xml files and when rebuilt all is on classes folder.
That simplicity was all the problem and solution!
Till the next

Naty


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