开发者

HQL JOIN Problem

开发者 https://www.devze.com 2023-02-16 02:01 出处:网络
I have 2 classes: ClassRoom, Student Cl开发者_开发百科ass Student { private Integer id; private ClassRoom classRoom;

I have 2 classes: ClassRoom, Student

Cl开发者_开发百科ass 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 */
}

What is the HQL to select all ClassRooms which have studens called John?


Option 1:

select distinct ClassRoom
from Student
where Name = 'John'

Option 2:

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


Try

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

You will need to use the fully qualified (with namespaces) names for your class.

Also, if the name is coming from the client, you should use a parameter (eg. :name)

0

精彩评论

暂无评论...
验证码 换一张
取 消