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)
精彩评论