• 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
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

hibernate.cfg.xml required in version 2.x?

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I had Hibernate 1.2 working okay in a simple junit test. Now I am trying to get it working in an simple Struts application. I have two questions:

1. Is is now required to provide a hibernate.cfg.xml file? Whenever I try to run a new test with the 2.1 version of Hibernate, I get the following error:
net.sf.hibernate.HibernateException: /hibernate.cfg.xml not found

2. Where do I put the hibernate.properties and hibernate.cfg.xml files? I thought that putting them into the WEB-INF/classes folder would work, but I am hoping someone can confirm.
 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Lance Hill:
I had Hibernate 1.2 working okay in a simple junit test. Now I am trying to get it working in an simple Struts application. I have two questions:

1. Is is now required to provide a hibernate.cfg.xml file? Whenever I try to run a new test with the 2.1 version of Hibernate, I get the following error:
net.sf.hibernate.HibernateException: /hibernate.cfg.xml not found


Make sure you have hibernate.cfg.xml in the classpath.


2. Where do I put the hibernate.properties and hibernate.cfg.xml files? I thought that putting them into the WEB-INF/classes folder would work, but I am hoping someone can confirm.


You don't need both the files. You can either have a properties file or an xml file for configuration. WEB-INF/classes is fine.
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I had the same problem and got it solved.

1) hibernate.cfg.xml into WEB-INF/classes/
2) obtain an URL to this file
URL url = MyClass.class.getResource("/hibernate.cfg.xml");
Make sure MyClass is part of your web-app
3) Configure hibernate
new Configuration().configure(url);
 
Ranch Hand
Posts: 995
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I would like to add that you must be carefull to create only one time the SessionFactory as this is quite a consuming task.

./pope
 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How can I add the hibernate.cfg.xml to the classpath ?

Under Eclipse, it is allowed to add only jar files ?

I'm developping a standalone application and using hibernate Synchronizer.
 
Alexandru Popescu
Ranch Hand
Posts: 995
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You just need to add to classpath the directory containing the xml file .

./pope
 
Filipe Marques
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank You!
It works.

I still have a problem. The mapping files are not found.
 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How do you make sure you are only loading sessionFactory once in a web app? With a singleton, or at server startup time? When do you clean it up? Thanks,
 
Alexandru Popescu
Ranch Hand
Posts: 995
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is presented very detailed on the Hibernate official reference first chapter: Quickstart with Tomcat.

./pope
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
We had the 'hibernate.cfg.xml not found' problem when developing
IBM WebSphere Portalserver portlets with struts and hibernate.

The solution was to have the hibernate.cfg.xml in WebSphere
Application Developer in ./JavaSources and get the hibernate
configuration at runtime this way:

File f=new File(servlet.getServletContext()
.getRealPath("/WEB-INF/classes/hibernate.cfg.xml"));

Configuration c = new Configuration().configure(f);

This is portable from WSAD to WPS

Bernd,
http://www.prolifics.de
 
Those who dance are thought mad by those who hear not the music. This tiny ad plays the bagpipes:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic