I have 2 object: Teacher and Student, they are many-to-many relationship. In Tearcher class it has a list of Students. I try to make a hql query to get all the teachers which have a student's name as "Peter". Currently I have 2 queries have seems to work properly:
1. select distinct t from Teacher t, Student s where s.name="Peter" and s=any elements(t.students)
2. select distinct t from Teacher t join t.students s where s.name="Peter"
Actually I didn't expect the second query can work before, but tried and it worked. I know elements(t.students) in the first query actually is a subquery, but not sure about the second one. Is anyone know how it worked and is it a subquery?
Many Thanks
|