Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

hibernate.cfg.xml not found

 
Akhilesh Trivedi
Ranch Hand
Posts: 1608
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I just created a struts project (in eclipse), created a bean "User" and two mapping files namely hibernate.cfg.xml and user.hbm.xml. I get

hibernate.cfg.xml not found error

on hitting the action where i have session/transaction statements. Any idea where should i dump it so that it is accessible, i tried moving it from web-inf to web-inf/lib. both dont seem to work.
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hibernate.cgf.xml needs to be at the root of your application's classpath if you are using the default configuration mechanism.
 
Akhilesh Trivedi
Ranch Hand
Posts: 1608
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Paul Sturrock:
hibernate.cgf.xml needs to be at the root of your application's classpath if you are using the default configuration mechanism.


It still did not work for me. Do I have a choice like property/config file where i can override the default configurations? what does it take to convert a simple web/java project into hibernate, other than having hibernate-jar to be in lib/classpath of the application. Currently my web.xml has no entries on on hbm/xml files.
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

It still did not work for me. Do I have a choice like property/config file where i can override the default configurations?

You can programatically override your configuration. See the JavaDocs for the Configuration class to see how.


what does it take to convert a simple web/java project into hibernate, other than having hibernate-jar to be in lib/classpath of the application.

Assuming you have hibernate.jar and all its dependencies in the class path it will work.


Currently my web.xml has no entries on on hbm/xml files.

It doesn't need any. Have you been through the quickstart?
 
Akhilesh Trivedi
Ranch Hand
Posts: 1608
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Paul. I left eclipse and came down to Textpad and ant. You were right, I simply had to dump the two xmls into classpath. That problem is solved, and it was not just hibernate-3.2.6.ga.jar there were other jars apart from apache-commons that i had to bring in, like cglib and asm I dont know what they do, but I feel I can still go ahead keeping the abstractions as is. My Hello world is still few steps away, (some jndi configurations to be looked into) but i think it will go smooth here after. Thank you very much again.
 
Timothy Sam
Ranch Hand
Posts: 751
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I only had to put hibernate.cfg.xml directly under my "src" folder in eclipse.
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Timothy Sam:
I only had to put hibernate.cfg.xml directly under my "src" folder in eclipse.


This is because by default in eclipse everything that is in your build path is also on your runtime classpath. This is not the case with JEE applications.
 
Akhilesh Trivedi
Ranch Hand
Posts: 1608
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes Timothy it works that way as well. I tried to save an object from session to the db and it has successfully inserted it, will explore more of it. Thanks.
 
Dan La
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try putting hibernate.cfg.xml under WEB-INF/classes/
[ December 09, 2008: Message edited by: Dan La ]
 
Akhilesh Trivedi
Ranch Hand
Posts: 1608
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Dan La:
Try putting hibernate.cfg.xml under WEB-INF/classes/

[ December 09, 2008: Message edited by: Dan La ]


The ant script does the same anyways.

Eclipse doesn't show me 'classes' folder(may be i will have to configure some perspectives or so). But i do hope it would be fine if I manually dump them on the app deployed on the server.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic