-->
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.  [ 2 posts ] 
Author Message
 Post subject: Newbie: One-to-Many Problems
PostPosted: Fri May 06, 2005 3:34 pm 
Newbie

Joined: Thu May 05, 2005 5:49 pm
Posts: 11
Location: San Diego, California
Hibernate 3.0
Oracle 9i

I am new to Hibernate (2 days) and am trying to get a one-to-many relationship to work. When I run my code I get the a message about an unmapped class. I'm sure this is simple, but I've been trying to solve this for over a day and am not getting it. I've followed the online documentation correctly (I think), but can't figure out the problem.

Thanks in advance.

Code:
org.hibernate.MappingException: Association references unmapped class: com.maximus.schoolmax.student.model.StudentVaccination
   at org.hibernate.cfg.HbmBinder.bindCollectionSecondPass(HbmBinder.java:1969)
   at org.hibernate.cfg.HbmBinder.bindMapSecondPass(HbmBinder.java:1888)
   at org.hibernate.cfg.HbmBinder$MapSecondPass.secondPass(HbmBinder.java:2456)
   at org.hibernate.cfg.HbmBinder$SecondPass.doSecondPass(HbmBinder.java:2392)
   at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:861)
   at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1049)
   at com.maximus.schoolmax.student.TestStudentModel.setUp(TestStudentModel.java:53)
   at com.intellij.rt.execution.junit2.JUnitStarter.main(JUnitStarter.java:31)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   at com.intellij.rt.execution.application.AppMain.main(AppMain.java:78)


Here is the Java code:

Code:
    public Long insertStudent()
    {
        String id = null;
        Student student = new Student();
        student.setDistrictNumber(DISTRICT_NUMBER);
        student.setExtStudentNumber(EXT_STUDENT_NUMBER);
        student.setDateOfBirth(BIRTH_DATE);
        student.setFirstName(FIRST_NAME);
        student.setMiddleName(MIDDLE_NAME);
        student.setLastName(LAST_NAME);
        student.setGender(GENDER);
        student.setHealthCompliant(new Integer(0));
        student.setUpdatedBy(UPDATED_BY);

        StudentVaccination sv = new StudentVaccination();
        sv.setAgeAtVaccination(4);
        sv.setUpdatedBy(UPDATED_BY);
        sv.setVaccinationDate(new Date());
        sv.setStudent(student);
        student.addVaccination(sv);
        session.save(student)


Here is the Student.hbm (this is the "1" in the relationship):
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping SYSTEM "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >

<hibernate-mapping package="com.maximus.schoolmax.student.model" >

<class name="Student"
      table="CE_FAMILY_MEMBER"
      lazy="true">

   <id name="studentId"
      type="long"
      column="STUDENT_ID"
      unsaved-value="0"
      access="org.hibernate.property.DirectPropertyAccessor">
      <generator class="sequence">
                <param name="sequence">CE_FAMILY_MBR_SEQ</param>
        </generator>
   </id>

    <property   name="firstName"
            column="FIRST_NAME"
            type="java.lang.String"
            update="true"
            not-null="true"
            access="org.hibernate.property.DirectPropertyAccessor"/>

   <property   name="middleName"
            column="MIDDLE_NAME"
            type="java.lang.String"
            update="true"
            not-null="true"
            access="org.hibernate.property.DirectPropertyAccessor"/>

   <property   name="lastName"
            column="LAST_NAME"
            type="java.lang.String"
            update="true"
            not-null="true"
            access="org.hibernate.property.DirectPropertyAccessor"/>

   <property   name="gender"
            column="GENDER"
            type="java.lang.String"
            update="true"
            not-null="true"
            access="org.hibernate.property.DirectPropertyAccessor"/>

   <property   name="dateOfBirth"
            column="DATE_OF_BIRTH"
            type="java.util.Date"
            update="true"
            not-null="true"
            access="org.hibernate.property.DirectPropertyAccessor"/>

   <property   name="healthCompliant"
            column="HEALTH_COMPLIANT"
            type="java.lang.Integer"
            update="true"
            not-null="false"
            access="org.hibernate.property.DirectPropertyAccessor"/>

   <property   name="extStudentNumber"
            column="EXT_STUDENT_NUMBER"
            type="java.lang.String"
            update="true"
            not-null="true"
            access="org.hibernate.property.DirectPropertyAccessor"/>

    <property   name="updatedBy"
                column="UPDATED_BY"
                type="java.lang.Long"
                update="true"
                not-null="true"
                access="org.hibernate.property.DirectPropertyAccessor"/>

    <property   name="updatedTime"
                column="UPDATE_TS"
                type="java.util.Date"
             update="true"
             not-null="true"
                access="org.hibernate.property.DirectPropertyAccessor"/>

    <property   name="districtNumber"
                column="DISTRICT_NUMBER"
                type="java.lang.Integer"
                update="true"
                not-null="true"
                access="org.hibernate.property.DirectPropertyAccessor"/>

    <property   name="email"
                column="EMAIL"
                type="java.lang.String"
                update="true"
                not-null="false"
                access="org.hibernate.property.DirectPropertyAccessor"/>

    <map name="vaccinations" cascade="all" lazy="true">
        <key column="STUDENT_ID" not-null="true"/>
        <map-key formula="vaccinationId" type="java.lang.Long"/>
        <one-to-many class="StudentVaccination"/>
    </map>

    <map name="exemptions" cascade="all" lazy="true">
        <key column="STUDENT_ID" not-null="true"/>
        <map-key formula="exemptionId" type="java.lang.Long"/>
        <one-to-many class="StudentVaccExemption"/>
    </map>

</class>

</hibernate-mapping>


Here is the Vaccination.hbm (this is the "many" in the relationship):
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping SYSTEM
         "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >

<hibernate-mapping package="com.maximus.schoolmax.health.model" >

<class name="StudentVaccination"
      table="ST_STUDENT_VACCINATION"
      lazy="true">

   <id name="studentVaccId"
      type="long"
      column="STUDENT_VACC_ID"
      unsaved-value="0"
      access="org.hibernate.property.DirectPropertyAccessor">
      <generator class="sequence">
                <param name="sequence">STUDENT_VACC_SEQ</param>
        </generator>
   </id>

   <property   name="vaccinationDate"
            column="VACCINATION_DATE"
            type="java.util.Date"
            update="true"
            not-null="true"
            access="org.hibernate.property.DirectPropertyAccessor"/>

   <property   name="ageAtVaccination"
            column="AGE_AT_VACCINATION"
            type="java.lang.Integer"
            update="true"
            not-null="true"
            access="org.hibernate.property.DirectPropertyAccessor"/>

   <property   name="updatedBy"
            column="UPDATED_BY"
            type="java.lang.Long"
            update="true"
            not-null="false"
            access="org.hibernate.property.DirectPropertyAccessor"/>

    <property   name="updatedTime"
                column="UPDATED_TS"
                type="java.util.Date"
             update="true"
             not-null="true"
                access="org.hibernate.property.DirectPropertyAccessor"/>

</class>

</hibernate-mapping>


Top
 Profile  
 
 Post subject: Re: Newbie: One-to-Many Problems
PostPosted: Fri May 06, 2005 3:41 pm 
Expert
Expert

Joined: Mon Feb 14, 2005 12:32 pm
Posts: 609
Location: Atlanta, GA - USA
aidan wrote:
Hibernate 3.0
Oracle 9i

I am new to Hibernate (2 days) and am trying to get a one-to-many relationship to work. When I run my code I get the a message about an unmapped class. I'm sure this is simple, but I've been trying to solve this for over a day and am not getting it. I've followed the online documentation correctly (I think), but can't figure out the problem.

Thanks in advance.



Your exception says it can't find com.maximus.schoolmax.student.model.StudentVaccination

But your mapping contains the class com.maximus.schoolmax.health.model.StudentVaccination

Change the <one-to-many> mapping for the Student.vaccinations to
<one-to-many class="com.maximus.schoolmax.health.model.StudentVaccination"/>

because if you don't specify the full package, it defaults to the <hibernate-mapping package="com.maximus.schoolmax.student.model" >


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