Reputation: 13
I have one to many mapping, School with set of Students and I want to get just the schools in which all students have score greater the 3.
Following query did the job:
List list = session.createQuery("select school from School school join school.students st group by school.id having min(st.score) > 3").list();
But I'm wondering is there a shorter way, something like HQL build-in function to get same result.
Upvotes: 0
Views: 54
Reputation: 692073
You'll need a subquery:
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)
Upvotes: 1