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>