This week's book giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of Cloud Application Architecture Patterns: Designing, Building, and Modernizing for the Cloud and have Kyle Brown, Bobby Woolf and Joseph Yodor on-line!
See this thread for details.
  • 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
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

Where to put hibernate.cfg.xml in a web-app

 
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am developing a web-appliction using NetBeans IDE.

Also, I am using hibernate for database access.

Where should I put the hibrnate.cfg.xml file and other configuration(mapping) files for hibernate in the default directory structure provided by NetBeans?

Thanks in advance..
 
author and cow tipper
Posts: 5009
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Put it on your classpath, but more specifically, in a location that the classloader that loads and initializes the Configuration, or AnnotationConfiguration object, can find it.

In Eclipse, or Rational Application Developer/RSA I typically see a folder named src in the web app. I put my packages and classes in there:

src\com\mcnz\data\HibernateUtil.java

In this case, I would place the hibernate.cfg.xml file in the src folder:

src\hibernate.cfg.xml

You would put your log4j.properties file in the same location.

The other important thing is to make sure that your hibernate.cfg.xml file gets moved to your build folder during deployment as well.

Now, you might actually want to code your Hibernate specific stuff outside of a web app, in an isolated, reusable, testable, Java project. Then your web app can just link to this Java project/jar file when needed. Still, the same rules apply. Just make sure the hibernate.cfg.xml file can be found by the Configuration object that gets initialized.

-Cameron McKenzie
[ May 26, 2008: Message edited by: Cameron Wallace McKenzie ]
 
Ranch Hand
Posts: 129
Firefox Browser Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Cameron Wallace McKenzie wrote:Put it on your classpath, but more specifically, in a location that the classloader that loads and initializes the Configuration, or AnnotationConfiguration object, can find it.

In Eclipse, or Rational Application Developer/RSA I typically see a folder named src in the web app. I put my packages and classes in there:

src\com\mcnz\data\HibernateUtil.java

In this case, I would place the hibernate.cfg.xml file in the src folder:

src\hibernate.cfg.xml

You would put your log4j.properties file in the same location.

The other important thing is to make sure that your hibernate.cfg.xml file gets moved to your build folder during deployment as well.

Now, you might actually want to code your Hibernate specific stuff outside of a web app, in an isolated, reusable, testable, Java project. Then your web app can just link to this Java project/jar file when needed. Still, the same rules apply. Just make sure the hibernate.cfg.xml file can be found by the Configuration object that gets initialized.

-Cameron McKenzie
[ May 26, 2008: Message edited by: Cameron Wallace McKenzie ]



in netbeans It can be in default package.
Go to Source Packages and then to <default package> and place hibernate.cfg.xml

it will work (for me it worked )....
 
reply
    Bookmark Topic Watch Topic
  • New Topic