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 Mapping issue in 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 "Mapping issue in hibernate.cfg.xml" Watch "Mapping issue in hibernate.cfg.xml" New topic

Mapping issue in hibernate.cfg.xml

vivek dhiman
Ranch Hand

Joined: Aug 05, 2011
Posts: 151

Hi during the execution of simple Java Program Configuration file not able to load the .hbm file. I have done few example in netbeans but in eclipse this encountered. Below is my code under eclipse java project.

Below is my Main Class

My mapping file that is in com package :

My hibernate.cfg.xml that is under src :

I am getting the error :

Please help Don't let me to swich to Netbeans.
Reddy Prashanth
Ranch Hand

Joined: Aug 09, 2005
Posts: 61
In your hibernate.cfg.xml file, below line is not valid.
<mapping class="com.Person.hbm.xml"/>

For class attribute, use class name as below
<mapping class="com.fooPackage.AnotherModelClass" />

Or, use
<mapping resource="com/Person.hbm.xml"/>

Also, if you already mention the mapping file name or class name in the hibernate.cfg.xml, then below line is redundant.
Configuration cfg = new Configuration().addResource("person.hbm.xml").configure();
vivek dhiman
Ranch Hand

Joined: Aug 05, 2011
Posts: 151

Thanks Mr. Reddy. This works now, just made 2 changes.

This site is really good & popular just because this reason. Place where i was stuck from last 1 days solved in 1 hr.

thank you again.
I agree. Here's the link:
subject: Mapping issue in hibernate.cfg.xml
It's not a secret anymore!