I have just started with Hibernate and I'm reading the tutorial of this site
http://docs.jboss.org/hibernate/core/3.3/reference/en/html/tutorial.html#tutorial-firstapp-configurationI'm following the steps in eclipse, but I'm having some problems.
First of all in the hibernate.cfg.xml file when I try the mappings. I wrote this line as show in the tutorial
Code:
<mapping resource="org/hibernate/tutorial/domain/Event.hbm.xml"/>
But I get this error when I try to execute EventManager class.
Code:
250 [main] ERROR org.hibernate.util.XMLHelper - Error parsing XML: XML InputStream(2) cvc-elt.1: Cannot find the declaration of element 'hibernate-mapping'.
Exception in thread "main" java.lang.ExceptionInInitializerError
at org.hibernate.tutorial.EventManager.listEvents(EventManager.java:43)
at org.hibernate.tutorial.EventManager.main(EventManager.java:18)
Caused by: org.hibernate.InvalidMappingException: Could not parse mapping document from resource org/hibernate/tutorial/domain/Event.hbm.xml
at org.hibernate.cfg.Configuration.addResource(Configuration.java:616)
at org.hibernate.cfg.AnnotationConfiguration.addResource(AnnotationConfiguration.java:957)
at org.hibernate.cfg.AnnotationConfiguration.parseMappingElement(AnnotationConfiguration.java:629)
at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:1603)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1582)
at org.hibernate.cfg.AnnotationConfiguration.doConfigure(AnnotationConfiguration.java:1047)
at org.hibernate.cfg.AnnotationConfiguration.doConfigure(AnnotationConfiguration.java:64)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1556)
at org.hibernate.cfg.AnnotationConfiguration.doConfigure(AnnotationConfiguration.java:1035)
at org.hibernate.cfg.AnnotationConfiguration.doConfigure(AnnotationConfiguration.java:64)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1476)
at org.hibernate.cfg.AnnotationConfiguration.configure(AnnotationConfiguration.java:1017)
at org.hibernate.cfg.AnnotationConfiguration.configure(AnnotationConfiguration.java:64)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1462)
at org.hibernate.cfg.AnnotationConfiguration.configure(AnnotationConfiguration.java:1011)
at org.hibernate.tutorial.util.HibernateUtil.<clinit>(HibernateUtil.java:13)
... 2 more
Caused by: org.hibernate.MappingException: invalid mapping
at org.hibernate.cfg.AnnotationConfiguration.addInputStream(AnnotationConfiguration.java:777)
at org.hibernate.cfg.AnnotationConfiguration.addInputStream(AnnotationConfiguration.java:64)
at org.hibernate.cfg.Configuration.addResource(Configuration.java:613)
... 17 more
Caused by: org.xml.sax.SAXParseException: cvc-elt.1: Cannot find the declaration of element 'hibernate-mapping'.
I have tried changing it by this code
Code:
<mapping class="org.hibernate.tutorial.domain.Event"/>
And now it works fine. I have searched but I can't find the difference between mapping a class and mapping resource.