Reputation: 6263
I am new to hibernate and i am having trouble with specifying the location of the mapping file in hibernate.cfg.xml file.
I have created an Event object in org.hibernate.tutorial.chapter1.domain.Event.java package with its corresponding Event.hbm.xml file in the same location.
I am trying to specify the location in the hibernate.cfg.xml mapping tag but I am getting an InvalidMappingException ().
I have added to the post: the exception, the mapping from the mapping file and the project file structure.
any advice would be great.
484 [main] ERROR org.hibernate.util.xml.ErrorLogger - Error parsing XML (1) : cvc-elt.1: Cannot find the declaration of element 'hibernate-mapping'. 495 [main] ERROR org.hibernate.util.xml.ErrorLogger - Error parsing XML (2) : cvc-elt.1: Cannot find the declaration of element 'hibernate-mapping'. Initial SessionFactory creation failed.org.hibernate.InvalidMappingException: Unable to read XML
<!-- Names the annotated entity class -->
<mapping resource="org/hibernate/tutorial/chapter1/domain/Event.hbm.xml"/>
Upvotes: 7
Views: 13033
Reputation: 89
My problem was that my XML file was missing :
<?xml version="1.0" encoding='utf-8'?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
after inserting this to the beginning of the XML file everything turned out great. Thanks!
Upvotes: 0
Reputation: 140061
Make sure you have a DOCTYPE in your Event.hbm.xml at the top of the XML content such as:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="org.hibernate.tutorial.domain">
[...]
</hibernate-mapping>
Upvotes: 14