title: Hibernate HBM Mapping Problem
body: <p>I have the following three classes:</p>
  
  <pre><code>public class Student {
      private Integer studentId;
      private StudentSchool studentSchool;
      private School school;
  
      public Integer getStudentId() {
          return studentId;
      }
      public void setStudentId(Integer studentId) {
          this.studentId = studentId;
      }
      public StudentSchool getStudentSchool() {
          return studentSchool;
      }
      public School getSchool() {
          return school;
      }
      public void setSchool(School school) {
          this.school = school;
      }
  }
  
  public class StudentSchool {
      private Student student;
      private School school;  
  
      public Student getStudent() {
          return student;
      }
      public void setStudent(Student student) {
          this.student = student;
      }
      public School getSchool() {
          return school;
      }
      public void setSchool(School school) {
          this.school = school;
      }
  }
  
  public class School {
      private Integer schoolId;
      private Set allStudents;
  
      public Integer getSchoolId() {
          return schoolId;
      }
      public void setSchoolId(Integer schoolId) {
          this.schoolId = schoolId;
      }
      public Set getAllStudents() {
          return allStudents;
      }
      public void setAllStudents(Set allStudents) {
          this.allStudents = allStudents;
      }
  }
  </code></pre>
  
  <p>I have the following DDL:</p>
  
  <pre><code>create table Student (StudentId Integer);
  create table StudentSchool (SchoolId Integer, StudentId Integer);
  create table School (SchoolId Integer Primary Key);
  </code></pre>
  
  <p>I have the following HBM files:</p>
  
  <p>School.hbm.xml</p>
  
  <pre><code>&lt;hibernate-mapping&gt;
      &lt;class name="School" table="School"&gt;
          &lt;property name="schoolId" type="integer" /&gt;
          &lt;set name="allStudents" table="StudentSchool" fetch="join"&gt;
              &lt;key column="schoolId" /&gt;
              &lt;composite-element class="StudentSchool"&gt;
                  &lt;parent name="school"/&gt;
                  &lt;many-to-one name="student" column="studentId" not-null="true" class="Student" /&gt;
              &lt;/composite-element&gt;
          &lt;/set&gt;
      &lt;/class&gt;
  &lt;/hibernate-mapping&gt;
  </code></pre>
  
  <p>Student.hbm.xml</p>
  
  <pre><code>&lt;hibernate-mapping&gt;
      &lt;class name="Student" table="Student"&gt;
          &lt;property name="studentId" type="integer" /&gt;
          &lt;one-to-one name="studentSchool" class="StudentSchool" /&gt;
          &lt;!-- &lt;one-to-one name="school" class="School" /&gt; --&gt;
      &lt;/class&gt;
  &lt;/hibernate-mapping&gt;
  </code></pre>
  
  <p>When I try to query the Student object based on the school, I get the following exception (even though I have a class called "StudentSchool" compiled in my classpath):</p>
  
  <pre><code>org.hibernate.MappingException: persistent class not known: StudentSchool
  </code></pre>
  
  <p>If I uncomment the one-to-one mapping to "School" and comment out the one-to-one mapping to "studentSchool", I get the following exception:</p>
  
  <pre><code>&lt;AST&gt;:1:143: unexpected AST node: : java.lang.NullPointerException
  </code></pre>
  
  <p>Does anyone have any ideas about what I did wrong with my hbm mapping? Thanks!</p>