当hibernate中难免遇到一对多的情况,并且需要对多方添加条件,使用sql查询会简单很多,hql的语法如下
Teacher对应下有多个Student
Teacher中Set<Student> students;
select s from Teacher t,Student s where t.tNo ='001' and s.sName like '张%' and s in elements(t.students)
为了方便理解,简单解释下意思:
Teacher的no为001 并且 Student姓张 并且 Student 属于Teacher的students中,
这样就能查询出编号为001的老师下所有姓张的学生了