-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 posts ] 
Author Message
 Post subject: XML parsing error reading mapping file
PostPosted: Wed Sep 28, 2005 5:10 am 
Newbie

Joined: Tue Sep 27, 2005 8:20 am
Posts: 2
Question description:

I am trying to run the example in the chapter 2 of Introduction to Hibernate, from the Hibernate Reference Manual at www.hibernate.org.
When reading the file Event.hbm.xml (creating the session) I get an XML parsing error :" Content is not allowed in trailing section". NO idea what it can be, but this file is just copy-pasted form the tutorial. Can u help me please?
Thanks!

Hibernate version:
Hibernate 3.0.5



Mapping documents:
Event.hbm.xml:

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping>
<class name="Event" table="EVENTS">
<!--
<id name="id" column="EVENT_ID">
<generator class="increment"/>
</id>
-->
<id name="id" column="EVENT_ID"/>

<property name="date" type="timestamp" column="EVENT_DATE"/>
<property name="title"/>
</class>
</hibernate-mapping>

Code between sessionFactory.openSession() and session.close():
Code from "Introduction to Hibernate,chapter 2" at www.hibernate.org.
Class EventManager:

private void createAndStoreEvent(String title, Date theDate) {
Session session = HibernateUtil.currentSession();
Transaction tx = session.beginTransaction();

Event theEvent = new Event();
theEvent.setTitle(title);
theEvent.setDate(theDate);

System.out.println("Event created. Goig to save");

session.save(theEvent);

System.out.println("Event saved. Goig to commit");

tx.commit();

HibernateUtil.closeSession();
}

Full stack trace of any exception that occurs:

[java] org.dom4j.DocumentException: Error on line 20 of document : Content is not allowed in trailing section. Nested exception: Content is not allowed in
ng section.
[java] at org.dom4j.io.SAXReader.read(SAXReader.java:482)
[java] at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:398)
[java] at org.hibernate.cfg.Configuration.addResource(Configuration.java:449)
[java] at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:1263)
[java] at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:1235)
[java] Initial SessionFactory creation failed.org.hibernate.MappingException: Error reading resource: Event.hbm.xml
[java] at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1217)
[java] Exception in thread "main" java.lang.ExceptionInInitializerError
[java] at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1184)
[java] at HibernateUtil.<clinit>(Unknown Source)
[java] at org.hibernate.cfg.Configuration.configure(Configuration.java:1112)
[java] at EventManager.createAndStoreEvent(Unknown Source)
[java] at org.hibernate.cfg.Configuration.configure(Configuration.java:1098)
[java] at EventManager.main(Unknown Source)
[java] at HibernateUtil.<clinit>(Unknown Source)
[java] Caused by: org.hibernate.MappingException: Error reading resource: Event.hbm.xml
[java] at EventManager.createAndStoreEvent(Unknown Source)
[java] at org.hibernate.cfg.Configuration.addResource(Configuration.java:452)
[java] at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:1263)
[java] at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:1235)
[java] at EventManager.main(Unknown Source)
[java] at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1217)
[java] Nested exception:
[java] at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1184)
[java] org.xml.sax.SAXParseException: Content is not allowed in trailing section.
[java] at org.hibernate.cfg.Configuration.configure(Configuration.java:1112)
[java] at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
[java] at org.hibernate.cfg.Configuration.configure(Configuration.java:1098)
[java] at org.dom4j.io.SAXReader.read(SAXReader.java:465)
[java] ... 3 more
[java] at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:398)
[java] Caused by: org.hibernate.MappingException: org.dom4j.DocumentException: Error on line 20 of document : Content is not allowed in trailing section. N
exception: Content is not allowed in trailing section.
[java] at org.hibernate.cfg.Configuration.addResource(Configuration.java:449)
[java] at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:408)
[java] at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:1263)
[java] at org.hibernate.cfg.Configuration.addResource(Configuration.java:449)
[java] at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:1235)
[java] ... 9 more
[java] at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1217)
[java] Caused by: org.dom4j.DocumentException: Error on line 20 of document : Content is not allowed in trailing section. Nested exception: Content is not
d in trailing section.
[java] at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1184)
[java] at org.dom4j.io.SAXReader.read(SAXReader.java:482)
[java] at org.hibernate.cfg.Configuration.configure(Configuration.java:1112)
[java] at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:398)
[java] at org.hibernate.cfg.Configuration.configure(Configuration.java:1098)
[java] ... 10 more
[java] at HibernateUtil.<clinit>(Unknown Source)
[java] at EventManager.createAndStoreEvent(Unknown Source)
[java] at EventManager.main(Unknown Source)
[java] Java Result: 1


Name and version of the database you are using:
MySQL 4.1 and HSQL DB, i get the same error using both.

The generated SQL (show_sql=true):
Nothing generated

Debug level Hibernate log excerpt:

[java] 10:32:32,437 INFO Environment:464 - Hibernate 3.0.5
[java] 10:32:32,437 INFO Environment:477 - hibernate.properties not found
[java] 10:32:32,437 INFO Environment:510 - using CGLIB reflection optimizer
[java] 10:32:32,453 INFO Environment:540 - using JDK 1.4 java.sql.Timestamp handling
[java] 10:32:32,531 INFO Configuration:1110 - configuring from resource: /hibernate.cfg.xml
[java] 10:32:32,531 INFO Configuration:1081 - Configuration resource: /hibernate.cfg.xml
[java] 10:32:32,828 DEBUG DTDEntityResolver:42 - trying to locate http://hibernate.sourceforge.net/hibern ... on-3.0.dtd in classpath under org/hib
e/
[java] 10:32:32,828 DEBUG DTDEntityResolver:53 - found http://hibernate.sourceforge.net/hibern ... on-3.0.dtd in classpath
[java] 10:32:32,890 DEBUG Configuration:1067 - connection.driver_class=com.mysql.jdbc.Driver
[java] 10:32:32,890 DEBUG Configuration:1067 - connection.url=jdbc:mysql://localhost/hibernatetest
[java] 10:32:32,890 DEBUG Configuration:1067 - connection.username=root
[java] 10:32:32,890 DEBUG Configuration:1067 - connection.password=bouw+123
[java] 10:32:32,890 DEBUG Configuration:1067 - connection.pool_size=1
[java] 10:32:32,890 DEBUG Configuration:1067 - dialect=org.hibernate.dialect.HSQLDialect
[java] 10:32:32,890 DEBUG Configuration:1067 - show_sql=true
[java] 10:32:32,890 DEBUG Configuration:1262 - null<-org.dom4j.tree.DefaultAttribute@a97b0b [Attribute: name resource value "Event.hbm.xml"]
[java] 10:32:32,890 INFO Configuration:444 - Mapping resource: Event.hbm.xml
[java] 10:32:32,890 DEBUG DTDEntityResolver:42 - trying to locate http://hibernate.sourceforge.net/hibern ... ng-3.0.dtd in classpath under org/hibernate

[java] 10:32:32,890 DEBUG DTDEntityResolver:53 - found http://hibernate.sourceforge.net/hibern ... ng-3.0.dtd in classpath
[java] 10:32:32,984 ERROR XMLHelper:59 - Error parsing XML: XML InputStream(20) Content is not allowed in trailing section.
[java] 10:32:32,984 ERROR Configuration:407 - Could not configure datastore from input stream
[java] org.dom4j.DocumentException: Error on line 20 of document : Content is not allowed in trailing section. Nested exception: Content is not allowed in t
ng section.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 28, 2005 5:26 am 
Senior
Senior

Joined: Thu Aug 04, 2005 4:54 am
Posts: 153
Location: Birmingham, UK
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping>
<class name="Event" table="EVENTS">
<!--
<id name="id" column="EVENT_ID">
<generator class="increment"/>
</id>
-->
<id name="id" column="EVENT_ID"/>  **THIS IS YOUR PROBLEM!

<property name="date" type="timestamp" column="EVENT_DATE"/>
<property name="title"/>
</class>
</hibernate-mapping>


You have <id name="id" column="EVENT_ID"/> a second time outside the <id></id> tags.

If you get xml errors compare your document against the DTD or use an editor capable of showing this sort of error.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 28, 2005 5:32 am 
Newbie

Joined: Tue May 17, 2005 10:55 am
Posts: 7
But it looks like the first ID element is commented out...

I would delete line 20 (the last line), as that is what the Exception is referring to. You might have a non-printable character there.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 28, 2005 5:33 am 
Newbie

Joined: Tue May 17, 2005 10:55 am
Posts: 7
But it looks like the first ID element is commented out...

I would delete line 20 (the last line), as that is what the Exception is referring to. You might have a non-printable character there.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 28, 2005 5:51 am 
Senior
Senior

Joined: Thu Aug 04, 2005 4:54 am
Posts: 153
Location: Birmingham, UK
I didn't even spot the comment. That'll teach me to read without putting it into a syntax colouring editor. Either way the file is still malformed xml. Id remove the line I pointed out and the comments.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 29, 2005 5:30 am 
Newbie

Joined: Tue Sep 27, 2005 8:20 am
Posts: 2
sdm wrote:
But it looks like the first ID element is commented out...

I would delete line 20 (the last line), as that is what the Exception is referring to. You might have a non-printable character there.


Thanks, it was indeed a non-printable charachter
Eduardo


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.