HQL JOIN问题

时间:2011-03-08 19:26:44

标签: hibernate join hql

我有2个课程: ClassRoom 学生

Class Student {
 private Integer id;
 private ClassRoom classRoom;
 private String name;

 /* GETTERS AND SETTER */
}


Class ClassRoom{
 private Integer id;
 private Set<Student> students;

 /* GETTERS AND SETTER */
}

HQL 是什么选择所有名为 John 的学生的ClassRooms?

2 个答案:

答案 0 :(得分:0)

尝试

from ClassRoom inner join Student as student where student.name = 'John'

您需要为您的班级使用完全限定(带名称空间)名称。

此外,如果名称来自客户端,则应使用参数(例如:名称)

答案 1 :(得分:0)

选项1:

select distinct ClassRoom
from Student
where Name = 'John'

选项2:

from ClassRoom c
where c in (select ClassRoom
            from Student
            where Name = 'John')