-->
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: org.hibernate.MappingException: Unknown entity
PostPosted: Thu Jun 19, 2008 2:05 pm 
Newbie

Joined: Thu Jun 19, 2008 1:49 pm
Posts: 2
Hibernate version: 3.0

Mapping documents:
hibernate.cfg.xml
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD//EN"
"http://localhost:8080/IPC-Implementation/hibernate-configuration-3.0.dtd">

<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">org.gjt.mm.mysql.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/ipcdb</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password">password</property>
<property name="show_sql">false</property>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>

<!-- Mapping files -->
<mapping resource="humanuser.hbm.xml" />
<mapping resource="student.hbm.xml" />
<mapping resource="professor.hbm.xml" />
<mapping resource="systemmanager.hbm.xml" />
<mapping resource="course.hbm.xml" />
<mapping resource="courseoffering.hbm.xml" />
<mapping resource="enrolment.hbm.xml" />
</session-factory>
</hibernate-configuration>


humanuser.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">
<hibernate-mapping package="SubsystemDesign.Didactics.Classes">
<class name="HumanUser" table="humanuser">
<id name="emailAddress" type="string" column="emailaddress">
<generator class="assigned"/>
</id>
<property name="name">
<column name="name"/>
</property>
<property name="surname">
<column name="surname"/>
</property>
<property name="ID_Number">
<column name="idnumber"/>
</property>
<property name="enabled">
<column name="enabled"/>
</property>
</class>
</hibernate-mapping>



student.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">
<hibernate-mapping package="SubsystemDesign.Didactics.Classes">
<joined-subclass name="Student" extends="HumanUser" table="student">
<key column="emailaddress"/>
<set name="enrolments">
<key column="student" not-null="true"/>
<one-to-many class="Enrolment"/>
</set>
</joined-subclass>
</hibernate-mapping>



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

Session s = sf.openSession();
Transaction t = s.beginTransaction();
t.begin();
s.save(this);
t.commit();


Full stack trace of any exception that occurs:
org.hibernate.MappingException: Unknown entity: SubsystemDesign.Didactics.Classes.Student
org.hibernate.impl.SessionFactoryImpl.getEntityPersister(SessionFactoryImpl.java:550)
org.hibernate.impl.SessionImpl.getEntityPersister(SessionImpl.java:1338)
org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:98)
org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:187)
org.hibernate.event.def.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:33)
org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:172)
org.hibernate.event.def.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:27)
org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:70)
org.hibernate.impl.SessionImpl.fireSave(SessionImpl.java:535)
org.hibernate.impl.SessionImpl.save(SessionImpl.java:523)
org.hibernate.impl.SessionImpl.save(SessionImpl.java:519)
SubsystemDesign.Didactics.Classes.HumanUser.store(HumanUser.java:251)
SubsystemDesign.Didactics.Classes.Student.create(Student.java:97)
SubsystemDesign.Didactics.Classes.StudentRegistrationController.createStudent(StudentRegistrationController.java:80)
SubsystemDesign.Didactics.Classes.AccountManagerDispatcher.createStudent(AccountManagerDispatcher.java:169)
SubsystemDesign.Didactics.Classes.StudentRegistrationServlet.doPost(StudentRegistrationServlet.java:96)
javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)




Name and version of the database you are using: MySQL 4.1

Note:
We are developing a web application with Eclipse. The application server classpath contains the directories:
<project root dir>
<project root dir>/build/classes

Both the cfg.xml file and the hbm.xml files are in <project root dir>/build/classes.

Thanks for your attention.


Top
 Profile  
 
 Post subject: java.lang.ExceptionInInitializerError
PostPosted: Fri Jun 20, 2008 6:06 am 
Newbie

Joined: Thu Jun 19, 2008 1:49 pm
Posts: 2
The previous problem was fixed placing the mapping files in the java files' directory, named <project root dir>/src/SubsystemDesign/Didactics/Classes

Therefore, the main mapping configuration file (hibernate.cfg.xml) looks like:
Code:
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD//EN"
"http://localhost:8080/IPC-Implementation/hibernate-configuration-3.0.dtd">

<hibernate-configuration>
<session-factory>
      <property name="hibernate.connection.driver_class">org.gjt.mm.mysql.Driver</property>
      <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/ipcdb</property>
      <property name="hibernate.connection.username">root</property>
      <property name="hibernate.connection.password">password</property>
      <property name="show_sql">true</property>
      <property name="dialect">org.hibernate.dialect.MySQLDialect</property>
     
      <!--  Mapping files -->
    <mapping resource="src/Subsystem/Didactics/SubsystemDesign/humanuser.hbm.xml" />
    <mapping resource="src/Subsystem/Didactics/SubsystemDesign/student.hbm.xml" />
    <mapping resource="src/Subsystem/Didactics/SubsystemDesign/professor.hbm.xml" />
    <mapping resource="src/Subsystem/Didactics/SubsystemDesign/systemmanager.hbm.xml" />
    <mapping resource="src/Subsystem/Didactics/SubsystemDesign/course.hbm.xml" />
    <mapping resource="src/Subsystem/Didactics/SubsystemDesign/courseoffering.hbm.xml" />
    <mapping resource="src/Subsystem/Didactics/SubsystemDesign/enrolment.hbm.xml" />   
</session-factory>
</hibernate-configuration>



The mapping files are:


humanuser.cfg.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="SubsystemDesign.Didactics.Classes">
  <class name="HumanUser" table="humanuser">
     <id name="emailAddress" type="string" column="emailaddress">
         <generator class="assigned"/>
     </id>
    <property name="name">
        <column name="name"/>
    </property>
    <property name="surname">
        <column name="surname"/>
    </property>
    <property name="ID_Number">
       <column name="idnumber"/>
    </property>
    <property name="enabled">
       <column name="enabled"/>
    </property>
  </class>
</hibernate-mapping>



student.cfg.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="SubsystemDesign.Didactics.Classes">
   <joined-subclass name="Student" extends="HumanUser" table="student">
     <key column="emailaddress"/>
     <set name="enrolments">
       <key column="student" not-null="true"/>
        <one-to-many class="Enrolment"/>
      </set>
    </joined-subclass>
</hibernate-mapping>



The code accessing Hibernate is the same posted previously, but now the exception stack trace is:

Code:
exception

javax.servlet.ServletException: Servlet execution threw an exception


root cause

java.lang.ExceptionInInitializerError
   java.lang.J9VMInternals.initialize(J9VMInternals.java:195)
   java.lang.J9VMInternals.initialize(J9VMInternals.java:144)
   SubsystemDesign.Didactics.Classes.StudentRegistrationController.createStudent(StudentRegistrationController.java:80)
   SubsystemDesign.Didactics.Classes.AccountManagerDispatcher.createStudent(AccountManagerDispatcher.java:169)
   SubsystemDesign.Didactics.Classes.StudentRegistrationServlet.doPost(StudentRegistrationServlet.java:96)
   javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
   javax.servlet.http.HttpServlet.service(HttpServlet.java:803)


root cause

org.hibernate.MappingException: Following superclasses referenced in extends not found: null[SubsystemDesign.Didactics.Classes]
   org.hibernate.cfg.Configuration.processExtendsQueue(Configuration.java:1209)
   org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1128)
   org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1292)
   SubsystemDesign.Didactics.Classes.HumanUser.<clinit>(HumanUser.java:23)
   java.lang.J9VMInternals.initializeImpl(Native Method)
   java.lang.J9VMInternals.initialize(J9VMInternals.java:177)
   java.lang.J9VMInternals.initialize(J9VMInternals.java:144)
   SubsystemDesign.Didactics.Classes.StudentRegistrationController.createStudent(StudentRegistrationController.java:80)
   SubsystemDesign.Didactics.Classes.AccountManagerDispatcher.createStudent(AccountManagerDispatcher.java:169)
   SubsystemDesign.Didactics.Classes.StudentRegistrationServlet.doPost(StudentRegistrationServlet.java:96)
   javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
   javax.servlet.http.HttpServlet.service(HttpServlet.java:803)




Just to point out, this web application runs on Tomcat 5.5.26. The application server is started from Eclipse workbench and the classpath contains <project root dir>, <project root dir>/WebContent (I mean the directories in the workspace, not those ones on the server, may it be a problem) and the default libraries added by Eclipse.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 23, 2008 9:59 am 
Expert
Expert

Joined: Tue May 13, 2008 3:42 pm
Posts: 919
Location: Toronto & Ajax Ontario www.hibernatemadeeasy.com
Just as a note, sometimes you'll see this problem when you have left the @Entity tag off a POJO when you're using Hibernate3 and JPA Annotations.

_________________
Cameron McKenzie - Author of "Hibernate Made Easy" and "What is WebSphere?"
http://www.TheBookOnHibernate.com Check out my 'easy to follow' Hibernate & JPA Tutorials


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.