Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mapping problem with Hibernate

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"/>

see below the project structure

like image 728
special0ne Avatar asked Apr 06 '11 23:04

special0ne


1 Answers

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>
like image 95
matt b Avatar answered Oct 12 '22 22:10

matt b