【发布时间】:2011-03-15 22:17:39
【问题描述】:
我的数据模型由学校和学生组成。学生拥有他们所属学校的 FK。 我不明白为什么该集合包含重复项,即 Joe、Joe、Mary、Mary、Tom、Tom 等 Hibernate 生成的 SQL 查询是正确的,不会返回重复的。 我可以实施一个 hack 来过滤掉重复项,但我还没有准备好忍受破窗户;) 我试图在下面粘贴相关的代码。非常感谢任何帮助!
// SchoolJpa
@OneToMany (
mappedBy = "school",
targetEntity = StudentJpa.class,
fetch = FetchType.LAZY,
cascade = CascadeType.ALL
)
@Override
public List<Student> getStudentsInternal() {
return super.getStudentsInternal();
}
// SchoolImpl
private List<Student> students = new ArrayList<Student>();
public List<Student> getStudents() {
return Collections.unmodifiableList(students);
}
public List<Student> getStudentsInternal() {
return students;
}
public void setStudentsInternal(List<Students> students) {
this.students = students;
}
【问题讨论】:
-
您用来检索对象的具体代码是什么? Hibernate 在某些类型的 HQL 中存在一些已知问题,这些问题会触发这样的重复。