• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Pranav Pal
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
  • 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..
 
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper
Posts: 4968
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • 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 ]
 
vijin das
Ranch Hand
Posts: 129
Firefox Browser Java Tomcat Server
  • Mark post as helpful
  • send pies
  • 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 )....
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic