• 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
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Hard to configurate Hibernate using NetBeans 5.5.1

 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
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
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
 
Ylva Degerfeldt
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
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

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
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Look ma! I'm selling my stuff!
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic