Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Hibernate: InvalidMappingException: Could not parse mapping document from resource

 
Joseph Sweet
Ranch Hand
Posts: 327
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:

 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Joseph Sweet
Ranch Hand
Posts: 327
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
[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.
 
Joseph Sweet
Ranch Hand
Posts: 327
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 327
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i guess that tutorial is way too old.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic