Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

InvalidMappingException

 
shah rah
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator






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
Pie
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
shah rah
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I followed this tutorial and it works fine now.

http://www.hibernate.org/hib_docs/v3/reference/en/html/tutorial-firstapp.html
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic