File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Object Relational Mapping and the fly likes InvalidMappingException  in Hibernate Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "InvalidMappingException  in Hibernate" Watch "InvalidMappingException  in Hibernate" New topic
Author

InvalidMappingException in Hibernate

Yewint Ko
Ranch Hand

Joined: Aug 02, 2009
Posts: 90
Hi all, I got thousand and thousand of errors using hibernate.This is my dir structure.


I use MySQL for database.I have these libs in the lib.

hibernate3.jar
antlr-2.7.6.jar
commons-collations-3.1.jar
dom4j-1.6.1.jar
javassist-3.9.0.GA.jar
jta-1.1.jar
slf4j-api1.5.8.jar
mysql-connector-java-5.1.9.jar

When I run , I got this error



and more error messages (in the case you want to see,I will show you later)

According to the error message , I think this error is from Employee.hbm.xml.So, the following is the content of that mapping file.



is something wrong with mapping file? Somebody help me please when you are free. I am in trouble.




Amar Deep Singh Chaudhary
Ranch Hand

Joined: Dec 26, 2006
Posts: 49
i am not able to see the Employee class in your structure, i think you have missed to display that, can you also upload the code of that class here , so that i can look into that and helpout you.

Thanks
With Regards
Amar Deep Singh
http://amardeep.100webspace.net

"A thinking mind never dies"
Yewint Ko
Ranch Hand

Joined: Aug 02, 2009
Posts: 90
oh sorry, I edited my structure.
and the code of Employee is as follow

Amar Deep Singh Chaudhary
Ranch Hand

Joined: Dec 26, 2006
Posts: 49
please also include your hibernate.cfg.xml file
Yewint Ko
Ranch Hand

Joined: Aug 02, 2009
Posts: 90
OK, this is my hibernate.cfg.xml



then I try to configure hibernate like this



I don't think there is something wrong with hibernate cfg file, may be the error comes from mapping hbm file.(in my case Employee.hbm.xml)
Yewint Ko
Ranch Hand

Joined: Aug 02, 2009
Posts: 90
Now I post the left error messages so that you will able to find out.

Christian Dillinger
Ranch Hand

Joined: Jul 20, 2009
Posts: 188
You don't have an id-Field. So this part of the class-Tag is missing: (id|composite-id)

You need an id oder composite-id.
Rahul Babbar
Ranch Hand

Joined: Jun 28, 2008
Posts: 210
Also a suggestion, if you have space before "<?xml version="1.0"?> ", remove it.
I remember getting this error for the space before the above.


Rahul Babbar
Yewint Ko
Ranch Hand

Joined: Aug 02, 2009
Posts: 90
Oh....yes, I got it. It works fine.Thanks you all.
But ,why do I have to add id field? Does it mean that every table in database must have ID column?
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: InvalidMappingException in Hibernate
 
Similar Threads
InvalidMappingException
Session throwing NullPointerException
hibernate error
Migration from Hibernate 2.0 to Hibernate 3.0