-->
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.  [ 5 posts ] 
Author Message
 Post subject: entity class not found
PostPosted: Mon Jul 16, 2007 4:45 am 
Newbie

Joined: Mon Jul 16, 2007 4:11 am
Posts: 3
hi,

i'm trying to use hibernate for a web application. i used hibernate tools and eclipse for reverse engineering all the code from an existing mysql 5 database.
the exporters i used are

- dao code
- hibernate xml mappings
- domain code

all the generated files are stored in the same directory. when i want to run a small test app, just to have a look if hibernate works correctly, it quits with the exception message

Initial SessionFactory creation failed. org.hibernate.MappingException: entity class not found: Relation

Relation is a table in my database. i've got an Relation.hbm.xml, Relation.java and RelationHome.java
everything is located in the same dir.

the mapping is, of course, done in the hibernate.cfg.xml
<mapping resource="fried/hibernate/src/Atribute.hbm.xml"/>
<mapping resource="fried/hibernate/src/AtttribValues.hbm.xml"/>
<mapping resource="fried/hibernate/src/Ci.hbm.xml"/>
<mapping resource="fried/hibernate/src/CiAttribute.hbm.xml"/>
<mapping resource="fried/hibernate/src/CiChange.hbm.xml"/>
<mapping resource="fried/hibernate/src/CiRelation.hbm.xml"/>
<mapping resource="fried/hibernate/src/CiType.hbm.xml"/>
<mapping resource="fried/hibernate/src/Datatype.hbm.xml"/>
<mapping resource="fried/hibernate/src/Event.hbm.xml"/>
<mapping resource="fried/hibernate/src/EventHistory.hbm.xml"/>
<mapping resource="fried/hibernate/src/GroupStandardAttributes.hbm.xml"/>
<mapping resource="fried/hibernate/src/Project.hbm.xml"/>
<mapping resource="fried/hibernate/src/Relation.hbm.xml"/>
<mapping resource="fried/hibernate/src/UserGroup.hbm.xml"/>
<mapping resource="fried/hibernate/src/UserProject.hbm.xml"/>
<mapping resource="fried/hibernate/src/UserTable.hbm.xml"/>

why does hibernate not find the class "Relation.java"? All other classes before "Relation" are seemingly found.

do you have any hints, what could be wrong? i guess, it's a newbie mistake but i don't have any clue.
is there the possibility, that this message could result out of an buggy "many-to-one" or "one-to-many" mapping?

i would be very pleased, if you could help me out, i've already spent so much time on this error.

thnx in advance, reverend

Hibernate version: Hibernate3

Code between sessionFactory.openSession() and session.close():

i use the "hinbernateutil" as described in the hibernate reference

Session sess = HibernateUtil.getSessionFactory().getCurrentSession();

sess.beginTransaction();

AtributeHome atHo = new AtributeHome();

List<Atribute> attList = atHo.findByExample(new Atribute());

for( int i = 0; i < attList.size(); i++){

System.out.println(attList.get(i).getAttributeType());
}

sess.close();


Full stack trace of any exception that occurs:

Name and version of the database: MySQL 5.x.x

Debug level Hibernate log excerpt:
09:56:50,992 INFO SessionFactoryImpl:161 - building session factory
09:56:51,007 DEBUG SessionFactoryImpl:173 - Session factory constructed with filter configurations : {}
09:56:51,007 DEBUG SessionFactoryImpl:177 - instantiating session factory with properties:
...
hibernate.bytecode.use_reflection_optimizer=false, hibernate.show_sql=true, java.vm.specification.version=1.0, sun.arch.data.model=32, java.home=G:\Program Files\Java\jre1.6.0_01, hibernate.connection.url=jdbc:mysql://localhost/cmdb, hibernate.dialect=org.hibernate.dialect.MySQLInnoDBDialect, java.specification.vendor=Sun Microsystems Inc., user.language=de, awt.toolkit=sun.awt.windows.WToolkit, java.vm.info=mixed mode,
...
Initial SessionFactory creation failed. org.hibernate.MappingException: entity class not found: Relation
Exception in thread "main" java.lang.ExceptionInInitializerError
at friedl.hibernate.util.HibernateUtil.<clinit>(HibernateUtil.java:30)
at friedl.hibernate.test.HibernateTest.main(HibernateTest.java:19)
Caused by: org.hibernate.MappingException: entity class not found: Relation
at org.hibernate.mapping.PersistentClass.getMappedClass(PersistentClass.java:99)
at org.hibernate.tuple.PropertyFactory.getGetter(PropertyFactory.java:168)
at org.hibernate.tuple.PropertyFactory.buildIdentifierProperty(PropertyFactory.java:44)
at org.hibernate.tuple.entity.EntityMetamodel.<init>(EntityMetamodel.java:123)
at org.hibernate.persister.entity.AbstractEntityPersister.<init>(AbstractEntityPersister.java:434)
at org.hibernate.persister.entity.SingleTableEntityPersister.<init>(SingleTableEntityPersister.java:109)
at org.hibernate.persister.PersisterFactory.createClassPersister(PersisterFactory.java:55)
at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:226)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1294)
at friedl.hibernate.util.HibernateUtil.<clinit>(HibernateUtil.java:22)


Last edited by reverend on Mon Jul 16, 2007 5:26 am, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 16, 2007 5:14 am 
Beginner
Beginner

Joined: Tue May 08, 2007 8:26 am
Posts: 21
Can you post the contents of the Relation.hbm.xml file ?
perhaps a spelling mistake is made in it (ie. mapping to Relation but inside the file it is named without a capital relation)


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 16, 2007 5:23 am 
Newbie

Joined: Mon Jul 16, 2007 4:11 am
Posts: 3
Relation.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">
<!-- Generated 12.07.2007 14:25:58 by Hibernate Tools 3.2.0.beta8 -->
<hibernate-mapping>
<class name="Relation" table="relation" catalog="cmdb">
<comment></comment>
<id name="id" type="int">
<column name="ID" />
<generator class="assigned" />
</id>
<property name="type" type="string">
<column name="type" length="50" not-null="true">
<comment></comment>
</column>
</property>
<set name="ciRelations" inverse="true">
<key>
<column name="rel_type_ID" not-null="true">
<comment></comment>
</column>
</key>
<one-to-many class="CiRelation" />
</set>
</class>
</hibernate-mapping>

and here is another mapping file, where the id of "relation" is used as foreign key
CiRelation.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">
<!-- Generated 12.07.2007 14:25:58 by Hibernate Tools 3.2.0.beta8 -->
<hibernate-mapping>
<class name="CiRelation" table="ci_relation" catalog="cmdb">
<comment></comment>
<id name="id" type="int">
<column name="ID" />
<generator class="assigned" />
</id>
<many-to-one name="ciByChildCiId" class="Ci" fetch="select">
<column name="child_ci_ID" not-null="true">
<comment></comment>
</column>
</many-to-one>
<many-to-one name="relation" class="Relation" fetch="select">
<column name="rel_type_ID" not-null="true">
<comment></comment>
</column>
</many-to-one>
<many-to-one name="ciByParentCiId" class="Ci" fetch="select">
<column name="parent_ci_ID" not-null="true">
<comment></comment>
</column>
</many-to-one>
</class>

i've already tried to use the full package name. as all the files are in the same folder, this shouldn't be a problem, isn't it?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 16, 2007 5:33 am 
Beginner
Beginner

Joined: Tue May 08, 2007 8:26 am
Posts: 21
As far as i know you do need to specify the full package name.
In the reference and in the declaration.

If not specified in class declaration i get a:
org.hibernate.MappingException: entity class not found: XXXX

(when not in reference:
org.hibernate.MappingException: An association from the table xxxx refers to an unmapped class: XXXX)

Try again with specifying the package name.

Btw when you specify it, do it in java style (ie. not com/test/Relation but com.test.Relation as opposed to the hibernate.cfg file which should have the slashes)


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 16, 2007 5:57 am 
Newbie

Joined: Mon Jul 16, 2007 4:11 am
Posts: 3
i've mapped all the classes with the full package name.

now, the "entity not found" error msg has disappeared.

thnx a lot for your help!


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