一个老师教多个学生,一个学生有多个老师。
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';
zz多对多关系中Set的查询
最新推荐文章于 2019-11-12 20:54:46 发布