多对多关系中Set的查询
一个老师教多个学生,一个学生有多个老师。
class Teacher { String id; String name; Set students; } class Student { String id; String name; Set teachers; } 现在要查询教某一个学生(name为xxx)的老师。 HSQL方法一:(性能最优) select elements(s.teachers) from Student s where s.name = 'xxx'; HSQL方法二:(要用到 inner join) select t from Teacher t join t.students s where s.name = 'xxx'; HSQL方法三:(要用到子查询) select t from Teacher t, Student s where s in elements(t.students) and s.name = 'xxx'; |