1

I am new to hibernate.. Iam using netbeans IDE and i setup every thing.. I placed all my stuff(configuration and mapping files) into a package called myfirsthibernate while running the sample application it is showing the error as couldn't find the file hibernate.cfg.xml. But it is there in myfirsthibernate package. How to rectify this and why this is happening??

Please help me and thanks..

3 Answers 3

3

By default, the hibernate.cfg.xml file is placed in /src/java/resource (which is in classpath by default directory). Could you please try placing the cfg file there?

Could you also give me some more info about the directory structure of your project.

Sign up to request clarification or add additional context in comments.

3 Comments

src->myfirsthibernate->hibernate.cfg.xml
directory: src/main/resources/hibernate.cfg.xml
It still not found in my case, I use netbeans and Windows as OS
1

The hibernate.cfg.xml needs to be in your classpath as well. Maybe write an ant task that automates this copying for you. Also, see hibernate.cfg.xml not found .

Comments

0

Assuming your project structure looks something like this src>myfirsthibernate>[some files], the Hibernate Documentation says hibernate expects to find the hibernate.cfg.xml file at the root of the classpath by default. So in order to start hibernate like this

SessionFactory sf = new Configuration().configure().buildSessionFactory();

your directory structure should look like this

>src
   >myfirsthibernate
      >[your entity classes and mapping files here]
   >hibernate.cfg.xml

If you wish to keep the file under myfirsthibernate package, then you need to add it's location during the configuration :

SessionFactory sf = new Configuration() .configure("myfirsthibernate/hibernate.cfg.xml") .buildSessionFactory();

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.