This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
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 OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA 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

karthik vraman
Greenhorn

Joined: Feb 21, 2005
Posts: 3
hi everyone,

i am a beginner to hibernate and i am having great difficulty in mapping the database. i am using jdk1.5(is it comaptible) and netbeans4.0 and hypersonic database (hsqldb 1.7.3).

whenever i run the program it does not detect either the hibernate.properties nor the hibernate.cfg.xml due to which i am unable to grasp anything about the working of hibernate.

whenever i use the command prompt for running a simple application it shows that jdbc connection not found.

can anybody help out with this.

karthik
Steven Bell
Ranch Hand

Joined: Dec 29, 2004
Posts: 1071
I also had some problems with the cfg.xml file. You might be able to get it by using ClassLoader.getResource(). I ended up putting the config in the code with a Configuration object. Not sure why it wouldn't pick it up.

P.S. I am using eclipse with MySQL and Java 1.4.2.
karthik vraman
Greenhorn

Joined: Feb 21, 2005
Posts: 3
hi steven

thanx for reply.
i will try the classloader.resource() and get back to you.

but still i want to know the reason for such variation.
has it got anything to do with the operating system?

karthik
David Harkness
Ranch Hand

Joined: Aug 07, 2003
Posts: 1646
Hibernate will look for its configuration file using the classpath. Put the directory containing hibernate.cfg.xml in the classpath. It will look by default for your mapping files in the same package/directory that contains the mapped class file.

If you're running this through an IDE, it's apparently extremely difficult to do this. It should be a single, simple step (Project : Properties : Add Directory to Class Path) but I guess no IDE supports this which cannot be the case, so look really hard in all those dialogs.

In our Ant scripts (we don't run anything through the IDE since no application is ever deployed inside an IDE), I have it copy all properties and xml files from src and test into the classes directory which is of course in the class path.
karthik vraman
Greenhorn

Joined: Feb 21, 2005
Posts: 3
hi

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.
Steven Bell
Ranch Hand

Joined: Dec 29, 2004
Posts: 1071
I've looked at the hibernate forum and it looks like the cfg.xml file must be in the 'classes' directory not the 'source'. I assume that means where you store your binaries so it would be the bin directory for me in eclipse. I will try that later tonight when I get home and see if it works.

P.S. When the project rebuilds it may erase the cfg.xml file so keep a copy. May need to copy the file over with an ant script when building.
[ February 22, 2005: Message edited by: Steven Bell ]
David Harkness
Ranch Hand

Joined: Aug 07, 2003
Posts: 1646
See Paul's post at the end of this other thread. In Eclipse there is a way to set it up so it copies files from your source directory to the classes directory after each build. Hopefully NetBeans has this feature as well.
 
Consider Paul's rocket mass heater.
 
subject: hibernate.cfg.xml not found