File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Object Relational Mapping and the fly likes what is the default location of hibernate.cfg.xml Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "what is the default location of hibernate.cfg.xml" Watch "what is the default location of hibernate.cfg.xml" New topic

what is the default location of hibernate.cfg.xml

sudheer kiran
Ranch Hand

Joined: Jun 26, 2008
Posts: 237

i am getting error,hibernate.cfg.xml not found
whille using return new Configuration().configure().buildSessionFactory();

what is the first location that hibernate will look for hibernate.cfg.xml.


Paul Sturrock

Joined: Apr 14, 2004
Posts: 10336

It needs to be on the classpath in the default package (i.e. in the folder all your classes are).

JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper

Joined: Aug 26, 2006
Posts: 4968

The question gets asked alot in here. Do a quick forum search and you'll find lots of people in the same shoes as you.

If you have folder such as \source that all your classes and packages are in, you typically put the hibernate-config.xml file in there. But remember, at runtime, it needs to be moved to your runtime classpath. Build tools usually compile and move Java code to a \build or \bin or \classes directory. Sometimes the config file doesn't get moved as well. So, make sure that config file is on the RUNTIME classpath, not just your build time classpath.

Here's a little tutorial I put together on setting up a Hibernate environment:

Getting Started with Hibernate - Configuring a Standard XP Environment

Good luck! If this doesn't help, tell us more about your environment.

-Cameron McKenzie
I agree. Here's the link:
subject: what is the default location of hibernate.cfg.xml
It's not a secret anymore!