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.
Joined: Feb 21, 2005
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?
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.
Joined: Feb 21, 2005
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.
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.
Joined: Dec 29, 2004
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 ]
Joined: Aug 07, 2003
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.