-->
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: net.sf.hibernate.MappingException
PostPosted: Sun Oct 05, 2003 9:43 pm 
Newbie

Joined: Sun Sep 14, 2003 8:29 pm
Posts: 6
Location: Tampa, FL
Hi,

I'm getting the following exception when trying to obtain a new Session:

net.sf.hibernate.MappingException: Association references unmapped class: com.groundswell.igrs.model.IGRSCourseDetail

I think it's related to an error in my hibernate mappings, which follow:

<hibernate-mapping>
<class name="com.groundswell.igrs.model.IGRSPeriod" table="tperiods">
<id name="periodId" type="long" column="period_id">
<generator class="increment"/>
</id>
<property name="periodNumber" column="period_number"/>
<property name="teacherId" column="teacher_id"/>
<property name="quarterId" column="quarter_id"/>

<many-to-one name="course" column="course_id" class="com.groundswell.igrs.model.IGRSCourse"/>

</class>

</hibernate-mapping>

<hibernate-mapping>
<class name="com.groundswell.igrs.model.IGRSCourse" table="tcourses">
<id name="courseId" type="long" column="course_id">
<generator class="increment"/>
</id>

<set name="courseDetails">
<key column="course_id"/>
<one-to-many class="com.groundswell.igrs.model.IGRSCourseDetail"/>
</set>
</class>

</hibernate-mapping>

<hibernate-mapping>
<class name="com.groundswell.igrs.model.IGRSCourseDetail" table="tcourse_details">
<id name="courseDetailId" type="long" column="course_detail_id">
<generator class="increment"/>
</id>
<!--<property name="courseId" column="course_id"/>-->
<property name="courseName" column="course_name"/>
<property name="locale" column="locale"/>

</class>

</hibernate-mapping>

Here's an explanation of why I have this model.

Basically, in my Java object model I have a Period class which is described by a Course (eg. "first" period could be described as "Algegra I"). The description however, can be localized. So I've created a third class to hold the localized description: CourseDetail.

On the database model side, I have three tables. The Periods table, which has a FK course_id to the Courses table (many-to-one) relationship. The CourseDetails table contains all of the localized course descriptions (names). I have a one-to-many relationship from Courses to CourseDetails, since each course would have a description for each locale.

When I load a Period, I also want the related Course and all of it's CoursDetails to load.

I'm sure that this "localization" pattern is quite common in DB models. But I'm having some trouble understanding how to map it properly with Hibernate.

Thanks in advance,
Matt


Top
 Profile  
 
 Post subject:
PostPosted: Sun Oct 05, 2003 10:43 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
Not sure if you simplified the mappings just for posting here, but if CourseDetail is really just the locale -> name mapping have you considered a java.util.Map approach? That's a really nice way to deal with localization issues.

Anyway, your mappings look fine. Are you certain you defined the CourseDetail class to the Hibernate configuration prior to obtaining the session factory? How are you doing this config? Also, try turning logging on to debug to make sure it finds the mapping for CourseDetail.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Oct 05, 2003 11:10 pm 
Newbie

Joined: Sun Sep 14, 2003 8:29 pm
Posts: 6
Location: Tampa, FL
Steve,

Here's the section of log, just prior to the exception (I've removed a big Hibernate DEBUG chunk that ouput a bunch of properties). I can see Hibernate processing the Period mapping, then the Course mapping. It then tries to resolve the courseDetails collection at which point it chokes.

(Configuration.java:836) DEBUG - null<-org.dom4j.tree.DefaultAttribute@1283052 [Attribute: name resource value "IGRSPeriod.hbm.xml"]
(Configuration.java:270) INFO - Mapping resource: IGRSPeriod.hbm.xml
(DTDEntityResolver.java:20) DEBUG - trying to locate http://hibernate.sourceforge.net/hibern ... ng-2.0.dtd in classpath under net/sf/hibernate/
(DTDEntityResolver.java:29) DEBUG - found http://hibernate.sourceforge.net/hibern ... ng-2.0.dtd in classpath
(Binder.java:178) INFO - Mapping class: com.groundswell.igrs.model.IGRSPeriod -> tperiods
(Binder.java:394) DEBUG - Mapped property: periodId -> period_id, type: long
(Binder.java:394) DEBUG - Mapped property: periodNumber -> period_number, type: integer
(Binder.java:394) DEBUG - Mapped property: teacherId -> teacher_id, type: long
(Binder.java:394) DEBUG - Mapped property: quarterId -> quarter_id, type: long
(Binder.java:394) DEBUG - Mapped property: course -> course_id, type: com.groundswell.igrs.model.IGRSCourse
(Configuration.java:836) DEBUG - null<-org.dom4j.tree.DefaultAttribute@15b8520 [Attribute: name resource value "IGRSCourse.hbm.xml"]
(Configuration.java:270) INFO - Mapping resource: IGRSCourse.hbm.xml
(DTDEntityResolver.java:20) DEBUG - trying to locate http://hibernate.sourceforge.net/hibern ... ng-2.0.dtd in classpath under net/sf/hibernate/
(DTDEntityResolver.java:29) DEBUG - found http://hibernate.sourceforge.net/hibern ... ng-2.0.dtd in classpath
(Binder.java:178) INFO - Mapping class: com.groundswell.igrs.model.IGRSCourse -> tcourses
(Binder.java:394) DEBUG - Mapped property: courseId -> course_id, type: long
(Binder.java:394) DEBUG - Mapped property: courseDetails, type: java.util.Set
(Configuration.java:885) INFO - Configured SessionFactory: null
(Configuration.java:492) INFO - processing one-to-many association mappings
(Binder.java:1134) DEBUG - Second pass for collection: com.groundswell.igrs.model.IGRSCourse.courseDetails
(GSHibernateDao.java:102) ERROR - currentSession(): Error getting new session...
hibernate.MappingException: Association references unmapped class: com.groundswell.igrs.model.IGRSCourseDetail


You asked:
"Are you certain you defined the CourseDetail class to the Hibernate configuration prior to obtaining the session factory? How are you doing this config?"

I'm not too cerain what you mean by this? I basically have an XXX.hbm.xml file for each of the three classes: Period, Course, CourseDetail. These are all placed in the app's WEB-INF/classes directory.

The SessionFactory is getting created when my first DAO method call is made. I'm using a class similar to the HibernateSession class example on the Hibernate site. My configuration is in a single hibernate.cfg.xml and I'm not using JNDI. Is this what you were asking?

I don't ever see where Hibernate is trying to load the IGRSCourseDetail map. (i.e. no message: "Mapping resource: IGRSCourseDetail" in the log anywhere).

Do you have any ideas for troubleshooting this further?

Thanks again for the help. I appreciate it.

Matt


Top
 Profile  
 
 Post subject:
PostPosted: Sun Oct 05, 2003 11:17 pm 
Newbie

Joined: Sun Sep 14, 2003 8:29 pm
Posts: 6
Location: Tampa, FL
Steve,

O.K., I'm a moron.


Didn't have the IGRSCourseDetail.hbm.xml listed in my hibernate.cfg.xml.

I appreciate your help. Your questions helped expose the problem!


thanks,
matt


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 06, 2003 12:08 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
NP...

If your interested, here is what it would look like using a map for the localization:
Code:
<hibernate-mapping>
    <class name="IGRSCourse" table="tcourses">
        <id name="courseId" type="long" column="course_id">
            <generator class="increment"/>
        </id>
        <map name="courseDetails" table="tcourse_details">
            <key column="course_id"/>
            <index column="locale" type="locale"/>
            <element column="course_name" type="string"/>
        </map>
    </class>
</hibernate-mapping>


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 06, 2003 9:31 pm 
Newbie

Joined: Sun Sep 14, 2003 8:29 pm
Posts: 6
Location: Tampa, FL
Steve,

Thanks. Great idea. I'll give it a shot.

Again, you're hepl was definitely appreciated.

matt


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 06, 2003 9:53 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
Grrr, i just noticed tampa... You're lucky I did not see that before (I'm a huge Phila. Eagles fan ;)


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 07, 2003 11:36 pm 
Newbie

Joined: Sun Sep 14, 2003 8:29 pm
Posts: 6
Location: Tampa, FL
LOL. Too good!

I'm going to have to make my profile less descriptive. ;-)

matt


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.