File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Object Relational Mapping and the fly likes Hard to configurate Hibernate using NetBeans 5.5.1 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of JavaScript Promises Essentials this week in the JavaScript forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Hard to configurate Hibernate using NetBeans 5.5.1" Watch "Hard to configurate Hibernate using NetBeans 5.5.1" New topic
Author

Hard to configurate Hibernate using NetBeans 5.5.1

Ylva Degerfeldt
Ranch Hand

Joined: Feb 12, 2008
Posts: 30
Hi everyone,

I'm having some trouble with configurating Hibernate with NetBeans 5.5.1.

I'm using Hibernate 3.0,
MySQL-5.0.51a
and Sun Java System Application Server 9.1.

I want to use the hibernate.cfg.xml file, which I've written with the help of some tutorials and the "Hibernate in Action" book, but I always get this error when trying to run the application in NetBeans:

"Initial SessionFactory creation failed.org.hibernate.HibernateException: /hibernate.cfg.xml not found"

I've tried to use a static util class for creating one Hibernate session and one Transaction and saving them in ThreadLocal objects (like in "Hibernate In Action", chapter 8) but since the hibernate.cfg.xml can't be found, that class can't be initialized and Hibernate can't be started.

I've read about other people with this problem but I haven't seen any good solution to it.

Currently I have Hibernate in the EJB module of an Enterprise Application (Maybe that's a bad idea. I don't know.) and I've tried moving the cfg.xml file around from the src\conf folder of the module to directly under src, directly under the src folder of the application and even to WEB-INF.
In those cases I've set the path to the file as argument to the configure method, (/WEB-INF/hibernate.cfg.xml in that case and the full physical file path in the other cases since I don't know the logical path), but that didn't help.
An example:


I also read that the cfg.xml file needs to be put in the class-path and that I have to make sure it gets copied to the build folder of the application but I don't know how to do that.(Changing some Ant script? But how?)
Is that what I need to do to make it work?

In that case, I need to know what files I need to change and how to write the code for that. My problem is that I know Java and writing source code but I don't know much about the internal workings of NetBeans and of how to configure everything I need for the project.

I'd be Very grateful for any kind of help on this matter. -If it's tips on actual coding or links to tutorials doesn't matter. I have read a lot and searched a lot on the Internet already and will continue to do so but since I Really need to finish this project soon I think I need some help from other people as well.
(By the way: Using another IDE than NetBeans 5.5.1 is not an option. This is a part of my thesis and I can't make such a change right now.)

Hoping to get some answers!
Thanks in advance,
Ylva
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17259
    
    6

Is the location you put your hibernate.cfg.xml in the root of your IDEs classpath? I think your NetBeans project doesn't have its classpath set correctly to pick up the location of your config file.

Mark


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

Joined: Feb 12, 2008
Posts: 30
I think it's not in the classpath, but I don't know how to put it there. Do you know? Please help!

/Ylva
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17259
    
    6

Originally posted by Ylva Degerfeldt:
I think it's not in the classpath, but I don't know how to put it there. Do you know? Please help!

/Ylva


Well, tell us your classpath?

Basically you have code that is in a package correct? So for instance, com.yourcompany.something. Well there is a directory structure which might be "c:\somedir\src\com\yourcompany\something" TO be in the class path, you probably have it set to "c:\somedir\src" So that would be the directory to put your config file.

Mark
Ylva Degerfeldt
Ranch Hand

Joined: Feb 12, 2008
Posts: 30
Thanks for the reply, Mark!

I just wanted to tell you that I solved it. The directory structure of the module where I keep the rest of my Hibernate files had a /src/java directory and that's where the cfg.xml file needed to be to make it work. (I still don't know where in NetBeans it is set that the config. file had to be right there but I have a shortage of time so I'd better just move on now.)

Thanks and have a nice day!

/Ylva
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Hard to configurate Hibernate using NetBeans 5.5.1