wood burning stoves 2.0*
The moose likes Object Relational Mapping and the fly likes Hibernate: InvalidMappingException: Could not parse mapping document from resource 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 "Hibernate: InvalidMappingException: Could not parse mapping document from resource" Watch "Hibernate: InvalidMappingException: Could not parse mapping document from resource" New topic
Author

Hibernate: InvalidMappingException: Could not parse mapping document from resource

Joseph Sweet
Ranch Hand

Joined: Jan 29, 2005
Posts: 327
Hi Everyone,

I am on Hibernate 3.2 and trying to use the following mapping but it keeps telling me something is wrong with my mapping file. However, I cannot see any clue as for what element/attribute is wrong....

It might be some of the elements are deprecated. I got the code from some online tutorial that seems to be quite old.

Any idea if there is some consistent way to find out what the problem with the mapping file is...?

Thanks.







And the stack trace:



We must know, we will know. -- David Hilbert
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

Um, I think it is the order of things you have in your xml

<hibernate-mapping>
<set role="names" table="names">

<set> is usually not right after a <hibernate-mapping> tag, <set> is usually a sub tag within the <class> tag.

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Joseph Sweet
Ranch Hand

Joined: Jan 29, 2005
Posts: 327
Yes, but from what I read they had done it on purpose.
Please compare what they did here:

http://www.xylax.net/hibernate/rawdata.html

to what they did here (which is the code from my 1st message):

http://www.xylax.net/hibernate/toplevel.html

Maybe there is something with the role attribute of the set element. From what I have seen in latter samples, it looks like they now use name instead of role. Is it true....? But then if I change the role to name in the the collection element... I end up with two name attributes....


[ November 15, 2007: Message edited by: Joseph Sweet ]
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 9957
    
163

[java] Caused by: org.dom4j.DocumentException: Connection timed out: connect Nested exception: Connection timed out: connect
[java] at org.dom4j.io.SAXReader.read(SAXReader.java:484)
[java] at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:499)


Looks like something to do with the dtd that you have defined in your mapping file. You said that you use Hibernate3, but the dtd still points to a older version:

<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN" "http://hibernate.sourceforge.net/hibernate-mapping-1.1.dtd">


As per the Hibernate migration guide, you will have to use the 3.0 dtd in the mappings. Here's an extract from the document:


DTD

Update the DTD reference in your hbm XML files. Change http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd to http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd in the DOCTYPE. If your application took 5 seconds to startup and now takes 50 with Hibernate3, you forgot to change the DTD. Hibernate will then try to lookup (and timeout) the DTD on the Internet for every mapping file instead of its JAR file.


See if changing that dtd, helps.


[My Blog] [JavaRanch Journal]
Joseph Sweet
Ranch Hand

Joined: Jan 29, 2005
Posts: 327
Okay I changed the DTD to the new one and there's a little progress although it's still not running.

I also changed the role attribute of the set element to be name.

So here is the new mapping file:



And here is the console:



It tells me there's an error on line 8: Attribute "type" must be declared for element type "key".

Huh? There is already a type attribute for the key element.
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 9957
    
163

The dtd does not allow a "type" for the "key" element. You will have to change your mapping file in accordance to the dtd
Joseph Sweet
Ranch Hand

Joined: Jan 29, 2005
Posts: 327
i guess that tutorial is way too old.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Hibernate: InvalidMappingException: Could not parse mapping document from resource
 
Similar Threads
InvalidMappingException
org.hibernate.MappingException: Association references unmapped class com.db.Soundtracks
problem with hibernate mapping
Hibernate App Issue
Invalid Mapping Exception while inserting data through hibernate