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 files not found
PostPosted: Wed Apr 18, 2007 9:51 am 
Beginner
Beginner

Joined: Thu Mar 29, 2007 11:57 am
Posts: 27
Hi,

I created a new dynamic web project using Eclipse. For the database access, I implemented the DAO pattern. The concrete DAO objects use Hibernate to access the database (PostgreSQL in my case).

I also use the HibernateUtil from the documentation which should return a SessionFactory. But when I start my software, this class throws an error because the initial SessionFactory creation failed. The Stacktrace tells that Hibernate is not able to find my mapping files. I don't know why the mapping files cannot be found because I wrote the full qualified path in the mappings section in my hibernate.cfg.xml.

My directory structure is the following (the hbm.xml files are all in the folder src/com/mycompany/datamgmt/dao/transferobjects):

projectFolder
├───.settings
├───build
│ └───classes
│ ├───com
│ │ └───mycompany
│ │ └───datamgmt
│ │ └───dao
│ │ ├───transferobjects
│ │ └───util
│ └───tests
├───docs
├───etc
├───lib
├───src
│ ├───com
│ │ └───mycompany
│ │ └───datamgmt
│ │ └───dao
│ │ ├───transferobjects
│ │ └───util
│ └───tests
└───WebContent
├───META-INF
└───WEB-INF
└───lib

Here is the StackTrace:
Code:
Initial SessionFactory creation failed. org.hibernate.MappingNotFoundException: resource: com.mycompany.datamgmt.dao.transferobjects/User.hbm.xml not found
java.lang.ExceptionInInitializerError
   at com.mycompany.datamgmt.dao.util.HibernateUtil.<clinit>(HibernateUtil.java:17)
   at com.mycompany.datamgmt.dao.UserDAOImpl.saveUser(UserDAOImpl.java:36)
   at tests.DAOTest.saveUser(DAOTest.java:20)
   at tests.DAOTest.main(DAOTest.java:26)
Caused by: org.hibernate.MappingNotFoundException: resource: com.mycompany.datamgmt.dao.transferobjects/User.hbm.xml not found
   at org.hibernate.cfg.Configuration.addResource(Configuration.java:563)
   at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:1587)
   at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:1555)
   at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1534)
   at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1508)
   at org.hibernate.cfg.Configuration.configure(Configuration.java:1428)
   at org.hibernate.cfg.Configuration.configure(Configuration.java:1414)
   at com.mycompany.datamgmt.dao.util.HibernateUtil.<clinit>(HibernateUtil.java:13)
   ... 3 more
Exception in thread "main"


Here is the 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>
        <property name="hibernate.bytecode.use_reflection_optimizer">false</property>
        <property name="hibernate.connection.driver_class">org.postgresql.Driver</property>
        <property name="hibernate.connection.password">xxxxxx</property>
        <property name="hibernate.connection.url">jdbc:postgresql://dbserver:1507/datamgmt</property>
        <property name="hibernate.connection.username">admin</property>
        <property name="hibernate.current_session_context_class">thread</property>
        <property name="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</property>
        <property name="hibernate.show_sql">true</property>
        <property name="hibernate.transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</property>

        <!-- Mapping files -->
      <mapping resource="com.mycompany.datamgmt.dao.transferobjects/User.hbm.xml"/>
      <mapping resource="com.mycompany.datamgmt.dao.transferobjects/Country.hbm.xml"/>
      <mapping resource="com.mycompany.datamgmt.dao.transferobjects/Vendor.hbm.xml"/>
    </session-factory>
</hibernate-configuration>


Here is the 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>
  <class name="com.mycompany.datamgmt.dao.transferobjects.User" table="tbl_user">
   <id name="id" type="java.lang.Long" column="id_user">
      <generator class="native"/>
   </id>
   <property name="surname">
      <column name="surname" />
    </property>
   <property name="firstname">
       <column name="firstname" />
    </property>
   <property name="email">
       <column name="email" />
    </property>
  </class>
</hibernate-mapping>


Here is the User class:
Code:
public class User {

   private Long id;
   
   private String surname;
   
   private String firstname;
   
   private String email;

   //getter and setter methods
}


I hope someone can help me.

Regards,
TMK


Top
 Profile  
 
 Post subject: Re: Mapping files not found
PostPosted: Wed Apr 18, 2007 10:01 am 
Expert
Expert

Joined: Fri Aug 19, 2005 2:11 pm
Posts: 628
Location: Cincinnati
less dots, more slashes.

change to:
Code:
...

        <!-- Mapping files -->
      <mapping resource="com/mycompany/datamgmt/dao/transferobjects/User.hbm.xml"/>
      <mapping resource="com/mycompany/datamgmt/dao/transferobjects/Country.hbm.xml"/>
      <mapping resource="com/mycompany/datamgmt/dao/transferobjects/Vendor.hbm.xml"/>
    </session-factory>
</hibernate-configuration>

_________________
Chris

If you were at work doing this voluntarily, imagine what you'd want to see to answer a question.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 18, 2007 11:30 am 
Beginner
Beginner

Joined: Thu Mar 29, 2007 11:57 am
Posts: 27
Thank you very much! This solved my problem.


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.