-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Problem with configurating Hibernate using NetBeans 5.5.1
PostPosted: Fri Jul 25, 2008 10:22 am 
Newbie

Joined: Fri Jun 13, 2008 4:52 pm
Posts: 9
Location: Västerås, Sweden
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:
Code:
sessionFactory = new Configuration()
                             .configure("C:\\Exjobb Ylva D\\Extract to cv 2\\Extract to cv 2-ejb\\src\\hibernate.cfg.xml")
                             .buildSessionFactory();


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


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jul 27, 2008 11:27 am 
Expert
Expert

Joined: Tue May 13, 2008 3:42 pm
Posts: 919
Location: Toronto & Ajax Ontario www.hibernatemadeeasy.com
Where is the Hibernate configuration file? Make sure it's on the classpath of the classloader for the Configuration object, that's where it needs to be.

Get Hibernate working first without using NetBeans, make sure it works, and then go to the tool. Check out this tutorial on setting up Hibernate:

Setting Up and Configuring Hibernate: A Tutorial

_________________
Cameron McKenzie - Author of "Hibernate Made Easy" and "What is WebSphere?"
http://www.TheBookOnHibernate.com Check out my 'easy to follow' Hibernate & JPA Tutorials


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 29, 2008 10:48 am 
Newbie

Joined: Fri Jun 13, 2008 4:52 pm
Posts: 9
Location: Västerås, Sweden
Thanks for the reply, Cameron!

I did start reading that tutorial and even started moving all my files to a place where I could test it without NetBeans but then someone said (concerning NetBeans 5.5.1) that I should put the hibernate.cfg.xml directly under the /src/java folder of the module, so I tried that and it actually worked. (I missed that one when I tried different locations.)

I'm still not sure Why it works (it's both a benefit and a drawback of NetBeans that it takes care of so much for you), but I don't have the time to ponder that any more now.

Thanks anyway and have a nice day!

/Ylva


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.