-->
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.  [ 8 posts ] 
Author Message
 Post subject: Problems mapping resources
PostPosted: Sun Feb 21, 2010 6:50 pm 
Newbie

Joined: Sun Feb 21, 2010 6:40 pm
Posts: 3
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-configuration
I'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.


Top
 Profile  
 
 Post subject: Re: Problems mapping resources
PostPosted: Mon Feb 22, 2010 1:16 am 
Newbie

Joined: Sun Feb 14, 2010 8:08 am
Posts: 12
"mapping resource" is used to specify the mapping that the resource should be used to resolve the mapping details. As in your example it is trying parse the file "Event.hbm.xml", which it is failing. Coming to "mapping class" its used when the class is using annotation for hibernate mapping. For more details go through http://docs.jboss.org/hibernate/stable/annotations/reference/en/html/ch01.html


Top
 Profile  
 
 Post subject: Re: Problems mapping resources
PostPosted: Mon Feb 22, 2010 4:56 am 
Newbie

Joined: Sun Feb 21, 2010 6:40 pm
Posts: 3
I don't understand why "mapping resource" is failing. The file Event.hbm.xml is in the specified path. What I'm doing wrong?


Top
 Profile  
 
 Post subject: Re: Problems mapping resources
PostPosted: Mon Feb 22, 2010 7:19 am 
Beginner
Beginner

Joined: Wed Nov 21, 2007 8:02 am
Posts: 48
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
        "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
        "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping package="org.hibernate.tutorial.domain">
<class name="Event" table="EVENTS">
...
</class>
</hibernate-mpaaing>


I guess you didn't include document type definition in your mapping file.


Last edited by kavithakaran on Mon Feb 22, 2010 8:27 am, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: Problems mapping resources
PostPosted: Mon Feb 22, 2010 8:03 am 
Newbie

Joined: Sun Feb 21, 2010 6:40 pm
Posts: 3
Hi kavithakaran,
I think you are right. I will try that when I arrive home and post the result.
Thanks


Top
 Profile  
 
 Post subject: Re: Problems mapping resources
PostPosted: Tue Jul 20, 2010 2:22 pm 
Newbie

Joined: Tue Jul 20, 2010 2:11 pm
Posts: 1
Maybe you didn't include the type definition or your file is not write correctly, I just finished the tutorial and I didn't have any problems on this part.


Top
 Profile  
 
 Post subject: Re: Problems mapping resources
PostPosted: Wed Aug 11, 2010 5:17 am 
Newbie

Joined: Wed Aug 11, 2010 4:54 am
Posts: 2
hi I have problem in the same part of tutorial, but my error is:
Code:
C:\Development\projects\test\HibernateTestApp>mvn exec:java -Dexec.mainClass="hibernate.tutorial.UserManager" -Dexec.args="nieco1 nieco2 nieco3"
[INFO] Scanning for projects...
[INFO] Searching repository for plugin with prefix: 'exec'.
[INFO] ------------------------------------------------------------------------
[INFO] Building HibernateTestApp
[INFO]    task-segment: [exec:java]
[INFO] ------------------------------------------------------------------------
[INFO] Preparing exec:java
[INFO] No goals needed for project - skipping
[INFO] [exec:java {execution: default-cli}]
SLF4J: The requested version 1.6 by your slf4j binding is not compatible with [1.5.5, 1.5.6, 1.5.7, 1.5.8]
SLF4J: See http://www.slf4j.org/codes.html#version_mismatch for further details.
9 [hibernate.tutorial.UserManager.main()] INFO org.hibernate.cfg.Environment - Hibernate 3.3.2.GA
10 [hibernate.tutorial.UserManager.main()] INFO org.hibernate.cfg.Environment - hibernate.properties not found
12 [hibernate.tutorial.UserManager.main()] INFO org.hibernate.cfg.Environment - Bytecode provider name : javassist
16 [hibernate.tutorial.UserManager.main()] INFO org.hibernate.cfg.Environment - using JDK 1.4 java.sql.Timestamp handling
61 [hibernate.tutorial.UserManager.main()] INFO org.hibernate.cfg.Configuration - configuring from resource: /hibernate.cfg.xml
62 [hibernate.tutorial.UserManager.main()] INFO org.hibernate.cfg.Configuration - Configuration resource: /hibernate.cfg.xml
118 [hibernate.tutorial.UserManager.main()] INFO org.hibernate.cfg.Configuration - Reading mappings from resource : hibernate/tutorial/domain/User.hbm.xml
Initial SessionFactory creation failed.org.hibernate.MappingNotFoundException: resource: hibernate/tutorial/domain/User.hbm.xml not found
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] An exception occured while executing the Java class. null

resource: hibernate/tutorial/domain/User.hbm.xml not found
[INFO] ------------------------------------------------------------------------
[INFO] For more information, run Maven with the -e switch
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1 second
[INFO] Finished at: Wed Aug 11 11:10:57 CEST 2010
[INFO] Final Memory: 11M/85M
[INFO] ------------------------------------------------------------------------
C:\Development\projects\test\HibernateTestApp>


hibernate.cfg.xml looks like this:
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"/>
    <!-- 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="hibernate/tutorial/domain/User.hbm.xml"/>
    </session-factory>
</hibernate-configuration>


has somebody any idea what did I wrong? its the 1.1.3 step in hibernate reference tutorial


Top
 Profile  
 
 Post subject: Re: Problems mapping resources
PostPosted: Wed Aug 11, 2010 5:38 am 
Newbie

Joined: Wed Aug 11, 2010 4:54 am
Posts: 2
so I solved it immediately after posting here, I had to copy the User.hbm.xml in the target folder, but I dont know why I had to do this manualy... why it is not autmatic? and if I guess right, its not mentioned in the tut
thanks :)


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