这个HQL查询是否有糖语法

时间:2015-01-04 10:16:39

标签: java hibernate hql

我有一对多的地图,学校有一套学生,我想得到所有学生得分高于3的学校。
以下查询完成了这项工作:

List list = session.createQuery("select school from School school join school.students st group by school.id having min(st.score) > 3").list(); 

但是我想知道是否有更短的方法,比如HQL内置函数可以得到相同的结果。

1 个答案:

答案 0 :(得分:1)

您需要一个子查询:

select school from School school where not exists(
    select student.id from School school2 
    join school2.students student 
    where student.score <= 3 
    and school2.id = school.id)
相关问题