-->
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: Mapping Configuration Resources from jar file
PostPosted: Fri Sep 16, 2005 2:41 pm 
Newbie

Joined: Fri Sep 16, 2005 2:20 pm
Posts: 4
I'm trying to map a ressource in the configuration file which is in an external JAR file included in the application's class path instead of having the object included in the main application package. Unfortunately I haven't been able to figure out how I should be mapping them in the hibernate.cfg.xml file.

Any help is appreciated.

Hibernate version:
3.1

Mapping documents:
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.postgresql.Driver</property>
      <property name="connection.url">jdbc:postgresql://localhost:5432/hdemo</property>
      <property name="connection.username">hdemo</property>
      <property name="connection.password">hdemo</property>
      <!-- JDBC connection pool (use the built-in) -->
      <property name="connection.pool_size">1</property>
      <!-- SQL dialect -->
      <property name="dialect">org.hibernate.dialect.PostgreSQLDialect</property>
      <!-- Echo all executed SQL to stdout -->
      <property name="show_sql">true</property>
      <!-- mapping files -->
      <mapping resource="com/lixar/pass/entity/User.hbm.xml" />
      <mapping resource="com/lixar/pass/entity/Group.hbm.xml" />
   </session-factory>
</hibernate-configuration>

*both *.hbm.xml files mentioned here are packaged in an external jar file

User.hbm.xml
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="com.lixar.pass.entity">
    <class name="User" table="`users`">
       <!-- PassEntity members -->
        <id name="id" column="`id`" type="java.lang.Integer">
            <generator class="increment"/>
        </id>
        <property name="isDisabled"/>
        <property name="isDeleted"/>
        <property name="createdOn" type="timestamp"/>
        <property name="updatedOn" type="timestamp"/>
        <many-to-one name="createdBy" class="User" column="userId"/>
        <many-to-one name="updatedBy" class="User" column="userId"/>
      <!-- Class Members -->
        <property name="username"/>
        <property name="passwd"/>
        <property name="firstName"/>
        <property name="lastName"/>
        <property name="email"/>
        <property name="telephone"/>
        <property name="telephoneExt"/>
        <property name="language"/>
        <many-to-one name="group" class="Group" column="groupId"/>
    </class>
</hibernate-mapping>


Group.hbm.xml
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="com.lixar.pass.entity">
    <class name="Group" table="`groups`">
       <!-- PassEntity members -->
        <id name="id" column="`id`" type="java.lang.Integer">
            <generator class="increment"/>
        </id>
        <property name="isDisabled"/>
        <property name="isDeleted"/>
        <property name="createdOn" type="timestamp"/>
        <property name="updatedOn" type="timestamp"/>
        <many-to-one name="createdBy" class="User" column="userId"/>
        <many-to-one name="updatedBy" class="User" column="userId"/>
        <!-- Class Members -->
        <property name="code"/>
        <property name="englishDescription"/>
        <property name="frenchDescription"/>
        <set role="users" table="`user`">
           <key column="groupId"/>
           <one-to-many class="User"/>
        </set>
    </class>
</hibernate-mapping>


Code between sessionFactory.openSession() and session.close():
N/A

Full stack trace of any exception that occurs:
Code:
log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
log4j:WARN Please initialize the log4j system properly.
Initial SessionFactory creation failed.org.hibernate.MappingException: Could not read mappings from resource: com/lixar/pass/entity/Group.hbm.xml
Exception in thread "main" java.lang.ExceptionInInitializerError
   at com.lixar.sears.hibernatetest.HibernateUtil.<clinit>(HibernateUtil.java:16)
   at com.lixar.sears.hibernatetest.EventManager.createUser(EventManager.java:17)
   at com.lixar.sears.hibernatetest.EventManager.main(EventManager.java:11)
Caused by: org.hibernate.MappingException: Could not read mappings from resource: com/lixar/pass/entity/Group.hbm.xml
   at org.hibernate.cfg.Configuration.addResource(Configuration.java:472)
   at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:1396)
   at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:1364)
   at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1345)
   at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1321)
   at org.hibernate.cfg.Configuration.configure(Configuration.java:1241)
   at org.hibernate.cfg.Configuration.configure(Configuration.java:1227)
   at com.lixar.sears.hibernatetest.HibernateUtil.<clinit>(HibernateUtil.java:12)
   ... 2 more
Caused by: org.hibernate.MappingException: invalid mapping
   at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:416)
   at org.hibernate.cfg.Configuration.addResource(Configuration.java:469)
   ... 9 more
Caused by: org.xml.sax.SAXParseException: Attribute "name" is required and must be specified for element type "set".
   at org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source)
   at org.apache.xerces.util.ErrorHandlerWrapper.error(Unknown Source)
   at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
   at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
   at org.apache.xerces.impl.dtd.XMLDTDValidator.addDTDDefaultAttrsAndValidate(Unknown Source)
   at org.apache.xerces.impl.dtd.XMLDTDValidator.handleStartElement(Unknown Source)
   at org.apache.xerces.impl.dtd.XMLDTDValidator.startElement(Unknown Source)
   at org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanStartElement(Unknown Source)
   at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)
   at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
   at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
   at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
   at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
   at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
   at org.dom4j.io.SAXReader.read(SAXReader.java:465)
   at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:413)
   ... 10 more


Name and version of the database you are using:
PostgreSQL 8.0.3

The generated SQL (show_sql=true):
N/A

Debug level Hibernate log excerpt:
N/A


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 16, 2005 2:47 pm 
Newbie

Joined: Tue May 11, 2004 10:47 am
Posts: 16
Look at the root (bottom) exception:

Quote:
Caused by: org.xml.sax.SAXParseException: Attribute "name" is required and must be specified for element type "set".



In Group.hbm.xml you don't have a name attribute for the set of users.

If this helps, please credit....


Luke


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 16, 2005 3:16 pm 
Newbie

Joined: Fri Sep 16, 2005 2:20 pm
Posts: 4
Well there was more to it than that but it seemed to be part of the problem and it set me on the right track to solving it, so points ahoy!

Thanks for the help.


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.