• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

hibernate.cfg.xml not found

 
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"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
 
Ranch Hand
Posts: 1646
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 1646
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 1646
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 1071
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I can't find this setting in Eclipse 3.0.1 or in Eclipse 2.1. Am I missing something?
 
Paul Sturrock
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes you are. Natalia Lopez is using JBuilderX....
[ February 23, 2005: Message edited by: Paul Sturrock ]
 
David Harkness
Ranch Hand
Posts: 1646
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oops, my bad. I sent Steven to this thread but didn't make the connection. Sorry Steven!
 
Ranch Hand
Posts: 1282
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
Natalia Lopez
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic