wood burning stoves*
The moose likes Object Relational Mapping and the fly likes InvalidMappingException Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "InvalidMappingException" Watch "InvalidMappingException" New topic
Author

InvalidMappingException

shah rah
Ranch Hand

Joined: Jan 04, 2007
Posts: 124






Following is printed
1.
2.
org.hibernate.InvalidMappingException: Could not parse mapping document from resource Login.hbm.xml

C:\myws\testhibernateproject\JavaSource\local\aaa\testhibernateproject\hiber
nate-->Login.java(POJO) and TestHibernate.java


c:\myws\testhibernateproject\WebContent\WEB-INF\classes-->

hibernate.cfg.xml
Login.hbm.xml

What is it that I am doing wrong?

[ October 21, 2008: Message edited by: shah rah ]
[ October 21, 2008: Message edited by: shah rah ]
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 9937
    
159

Is this all that you see in the exception? If not, please post the entire exception stacktrace. Also ensure that you have placed this hbm.xml file at the right location. What location have your specified in your hibernate.cfg.xml file? Can you post the contents of that file?


[My Blog] [JavaRanch Journal]
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
Is it because, the ID column is auto-increment in your actual database table? It should not, because you are implmenting auto-increment through Hibernate. It should be something like int, integer, number or something.

Lets give a try after changing.
shah rah
Ranch Hand

Joined: Jan 04, 2007
Posts: 124
Here is the code.. THere is no stack race and I get only one line of error

RAD: v6
Hibernate: hibernate-distribution-3.3.1.GA-dist.zip
mysqldrivwer: mysql-connector-java-5.1.6
JDK 1.5



C:\myws\testhibernateproject\WebContent\WEB-INF\classes\Login.hbm.xml



C:\myws\testhibernateproject\WebContent\WEB-INF\classes\Hibernate.cfg.xml---> the db connection works if I write a JDBC program with below parameters







C:\myws\testhibernateproject\JavaSource\local\aaa\testhibernateproject\hibernate\TestHibernate.java



[ October 22, 2008: Message edited by: shah rah ]
[ October 22, 2008: Message edited by: shah rah ]
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
There is no Exception stack trace in your post. From one of the line you mentioned, it looks it is unable to locate your Login.hbm.xml
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Why are you using hibernate.cfg.xml and configuring your SessionFactory programatically? Pick one or the other.

As Adeel mentions, the reason you see this is because Hibernate cannot find the mapping file you are trying to add to the configuration.

If you do this:

you asking Hibernate to find a resource called "Login.hbm.xml" that is located in the default package.

If you do this:

you are asking Hibernate to configure a resource from a file (assuming you are not using annotations) called "Login.hbm.xml" that sits in the same package as your class file. So if the fully qualified name of your class is local.aaa.testhibernateproject.hibernate.Login your mapping file must be in the folder local/aaa/testhibernateproject/hibernate/. Given Hibernate cannot find this file, I assume this is not the case.

If you do this:

you are asking Hibernate to configure a SessionFactory based on the resources it finds in hibernate.cfg.xml. Currently, this will require a file called "Login.hbm.xml" existing in the default package.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
shah rah
Ranch Hand

Joined: Jan 04, 2007
Posts: 124
I followed this tutorial and it works fine now.

http://www.hibernate.org/hib_docs/v3/reference/en/html/tutorial-firstapp.html
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: InvalidMappingException
 
Similar Threads
NullPointerException on SessionFactory sessionFactory = new Configuration().configure().buildSession
Not able to find the added record in table.
Error reading resource Hibernate
Problem in insert query
MappingNotFoundException