wood burning stoves 2.0*
The moose likes Object Relational Mapping and the fly likes hibernate.cfg.xml not found Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "hibernate.cfg.xml not found" Watch "hibernate.cfg.xml not found" New topic
Author

hibernate.cfg.xml not found

Natalia Lopez
Ranch Hand

Joined: Feb 17, 2005
Posts: 41
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
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

"Natalia"-
Welcome to the JavaRanch! Please adjust your displayed name to meet the

JavaRanch Naming Policy.

You can change it

here.

Thanks! and welcome to the JavaRanch!

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
David Harkness
Ranch Hand

Joined: Aug 07, 2003
Posts: 1646
Hibernate looks for that file to be in the root of one of the JARs or directories on the classpath. You should be able to add a directory to the classpath in JBuilder and put the file there.
Natalia Lopez
Ranch Hand

Joined: Feb 17, 2005
Posts: 41
Thank you for your help!!
I put the hibernate.cfg.xml on the class directory and work but still not found the maping.hbm.xml files.
The src directory is in the class path and I put hibernate.cfg.xml and the mapping.hbm.xml in the src directory. I wonder why they are not founded?
There is some option n JBuilder that reject .xml files in the src directory?
Regards

Naty
David Harkness
Ranch Hand

Joined: Aug 07, 2003
Posts: 1646
When you moved the hibernate.cfg.xml file from your classes directory to the source directory, did it still find it? If so, then clearly Hibernate will access XML files in the source tree. If this is the case, make sure your mapping files are where Hibernate expects them.

If you're telling Hibernate about a mapped class (rather than the file itself), Hibernate will look in the same package as the file. If you specify the file directly, double-check your paths. Also, maybe post up the code you're using to perform the configuration.

If you don't get it, I'll ask one of the developers on my team that uses Eclipse how they have it set up for running JUnit tests from Eclipse which require the mapping files.
Natalia Lopez
Ranch Hand

Joined: Feb 17, 2005
Posts: 41
Hi again
When you moved the hibernate.cfg.xml file from your classes directory to the source directory, did it still find it?
The answer is not
I put the mapped class in the same directory than the .java class definition as the documentation say.
I will go to apreciate some example in eclipse, maybe can help me !!!
Or maybe JBuilder need some other configuration I really don't know.
Just in case I'm using JBuilderX
King Regards

Naty
David Harkness
Ranch Hand

Joined: Aug 07, 2003
Posts: 1646
Well, none of us uses JBuilder anymore, but I'll ask if anyone remembers how to add the source directory to the class path. In the project properties, there should be a way to add any directory to the classpath, just like adding a JAR but maybe a different tab page. Is there nothing like that?
Natalia Lopez
Ranch Hand

Joined: Feb 17, 2005
Posts: 41
Yes I put in lib directory where I have the .jar 's files but still not work. Only find it If I put in classes directory but when I rebuilt the project I lost the file
I will write you If I get a solution
Thank you

Naty
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Look under Project Properties>Build>Resource there is a list of file types which will get copied as part of your build process. You should be able to add *.cfg.xml and *.hbm.xml (or possibly just *.xml) in there.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Steven Bell
Ranch Hand

Joined: Dec 29, 2004
Posts: 1071
I can't find this setting in Eclipse 3.0.1 or in Eclipse 2.1. Am I missing something?
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Yes you are. Natalia Lopez is using JBuilderX....
[ February 23, 2005: Message edited by: Paul Sturrock ]
David Harkness
Ranch Hand

Joined: Aug 07, 2003
Posts: 1646
Oops, my bad. I sent Steven to this thread but didn't make the connection. Sorry Steven!
miguel lisboa
Ranch Hand

Joined: Feb 08, 2004
Posts: 1281
log4j:WARN No appenders could be found for logger (net.sf.hibernate.cfg.Environment).

log4j:WARN Please initialize the log4j system properly.

this means you dont have a log4j.properties file in your classpath

imagine your root folder is:
MyProject
inside, you'll have two folders:
MyClasses and MySources
Inside each one you'll have a package named MyPackage where respectively you'll keep *.class and *.java files
Put hibernate.cfg.xml and log4j.properties inside:
MyProject/MyClasses

and later on add the *.hbm.xml to
MyProject/MyClasses/MyPackage,
together with your class files
hope this helps
good luck


java amateur
Natalia Lopez
Ranch Hand

Joined: Feb 17, 2005
Posts: 41
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
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: hibernate.cfg.xml not found
 
Similar Threads
having two hibernate.cfg.xml on the same project
log4j errors
hibernate.cfg.xml not found
Could not find a getter for id1 in class ........
regarding hibernate