Problème de cartographie HBM Hibernate
-
12-11-2019 - |
Question
J'ai les trois classes suivantes:
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;
}
}
J'ai le DDL suivant:
create table Student (StudentId Integer);
create table StudentSchool (SchoolId Integer, StudentId Integer);
create table School (SchoolId Integer Primary Key);
J'ai les fichiers HBM suivants:
École.hbm.xml
<hibernate-mapping>
<class name="School" table="School">
<property name="schoolId" type="integer" />
<set name="allStudents" table="StudentSchool" fetch="join">
<key column="schoolId" />
<composite-element class="StudentSchool">
<parent name="school"/>
<many-to-one name="student" column="studentId" not-null="true" class="Student" />
</composite-element>
</set>
</class>
</hibernate-mapping>
Étudiant.hbm.xml
<hibernate-mapping>
<class name="Student" table="Student">
<property name="studentId" type="integer" />
<one-to-one name="studentSchool" class="StudentSchool" />
<!-- <one-to-one name="school" class="School" /> -->
</class>
</hibernate-mapping>
Lorsque j'essaie de demander l'objet étudiant en fonction de l'école, je reçois l'exception suivante (même si j'ai une classe appelée "Studentschool" compilée dans mon chemin de classe):
org.hibernate.MappingException: persistent class not known: StudentSchool
Si je déconnecte la cartographie un à un à "l'école" et commentez la cartographie individuelle de "Studentschool", j'obtiens l'exception suivante:
<AST>:1:143: unexpected AST node: : java.lang.NullPointerException
Quelqu'un a-t-il des idées sur ce que j'ai fait de mal avec ma cartographie HBM? Merci!
Pas de solution correcte
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow