Hello
I'am learning Hibernate and working with Tutorial.
I'am stoped on "Part 2 mapping associations"
My all java file compilled properly: Person.java, Event.java, EvenManager.java, HibernateUtil.java.
I have two hibernate configurationfile Hibernate.cfg.xml, and Event.hbm.xml.
At this point I want save to Database only one entity Event but during running example I receiving exeption "Unable to read XML"
Code:
run:
[java] SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
[java] SLF4J: Defaulting to no-operation (NOP) logger implementation
[java] SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
[java] Initial SessionFactory creation failed.org.hibernate.InvalidMappingException: Unable to read XML
[java] Exception in thread "main" java.lang.ExceptionInInitializerError
[java] at org.hibernate.tutorial.util.HibernateUtil.buildSessionFactory(Unknown Source)
[java] at org.hibernate.tutorial.util.HibernateUtil.<clinit>(Unknown Source)
[java] at org.hibernate.tutorial.EventManager.createAndStoreEvent(Unknown Source)
[java] at org.hibernate.tutorial.EventManager.main(Unknown Source)
[java] Caused by: org.hibernate.InvalidMappingException: Unable to read XML
[java] at org.hibernate.util.xml.MappingReader.readMappingDocument(MappingReader.java:101)
[java] at org.hibernate.cfg.Configuration.add(Configuration.java:510)
[java] at org.hibernate.cfg.Configuration.add(Configuration.java:506)
[java] at org.hibernate.cfg.Configuration.add(Configuration.java:686)
[java] at org.hibernate.cfg.Configuration.addResource(Configuration.java:771)
[java] at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:2314)
[java] at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:2280)
[java] at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:2260)
[java] at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:2213)
[java] at org.hibernate.cfg.Configuration.configure(Configuration.java:2128)
[java] at org.hibernate.cfg.Configuration.configure(Configuration.java:2107)
[java] ... 4 more
[java] Caused by: org.xml.sax.SAXParseException: cvc-elt.1: Cannot find the declaration of element 'hibernate-mapping'.
[java] at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:195)
[java] at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.error(ErrorHandlerWrapper.java:131)
[java] at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:384)
[java] at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:318)
[java] at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.handleStartElement(XMLSchemaValidator.java:1916)
[java] at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.startElement(XMLSchemaValidator.java:705)
[java] at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanStartElement(XMLNSDocumentScannerImpl.java:400)
[java] at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl$NSContentDriver.scanRootElementHook(XMLNSDocumentScannerImpl.java:626)
[java] at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:3103)
[java] at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$PrologDriver.next(XMLDocumentScannerImpl.java:922)
[java] at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:648)
[java] at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(XMLNSDocumentScannerImpl.java:140)
[java] at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:511)
[java] at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:808)
[java] at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:737)
[java] at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:119)
[java] at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1205)
[java] at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:522)
[java] at org.dom4j.io.SAXReader.read(SAXReader.java:465)
[java] at org.hibernate.util.xml.MappingReader.readMappingDocument(MappingReader.java:75)
[java] ... 14 more
[java] Java Result: 1
I don't know it is important but I,am used ant instead of maven.
This is Hibernate.cfg.xml
Code:
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<!-- Database connection settings -->
<property name="connection.driver_class">org.hsqldb.jdbcDriver</property>
<property name="connection.url">jdbc:hsqldb:hsql://localhost</property>
<property name="connection.username">sa</property>
<property name="connection.password"></property>
<!-- JDBC connection pool (use the built-in) -->
<property name="connection.pool_size">1</property>
<!-- SQL dialect -->
<property name="dialect">org.hibernate.dialect.HSQLDialect</property>
<!-- Enable Hibernate's automatic session context management -->
<property name="current_session_context_class">thread</property>
<!-- Disable the second-level cache -->
<property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
<!-- Echo all executed SQL to stdout -->
<property name="show_sql">true</property>
<!-- Drop and re-create the database schema on startup -->
<property name="hbm2ddl.auto">update</property>
<mapping resource="org/hibernate/tutorial/domain/Event.hbm.xml"/>
</session-factory>
</hibernate-configuration>
and Person.hbm.xml
Code:
<hibernate-mapping package="org.hibernate.tutorial.domain">
<class name="Event" table="EVENTS">
<id name="id" column="EVENT_ID">
<generator class="native"/>
</id>
<property name="date" type="timestamp" column="EVENT_DATE"/>
<property name="title"/>
</class>
</hibernate-mapping>
What I'm doing wrong
Please Help