-->
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.  [ 3 posts ] 
Author Message
 Post subject: Problem with hibernate tutorial
PostPosted: Tue Feb 01, 2011 5:28 am 
Newbie

Joined: Tue Feb 01, 2011 5:10 am
Posts: 1
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


Top
 Profile  
 
 Post subject: Re: Problem with hibernate tutorial
PostPosted: Wed Feb 02, 2011 6:22 am 
Regular
Regular

Joined: Fri Jan 28, 2011 11:44 am
Posts: 117
I think you are missing this in the file Person.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">


Top
 Profile  
 
 Post subject: Re: Problem with hibernate tutorial
PostPosted: Sun Mar 20, 2011 3:32 pm 
Newbie

Joined: Sun Mar 20, 2011 3:24 pm
Posts: 1
Yes, in Hibernate.cfg.xml you have only add
<mapping resource="org/hibernate/tutorial/domain/Event.hbm.xml"/> you need to create and add Person.hbm.xml file.

You can follow this simple but good example.
http://blog.sencide.com/2011/03/hibernate-tutorial-for-beginners.html
It has source code included and you will be able to get good knowledge.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.