I have two objects named Parent and Child , connected in a one-to-many relationship . The child object has a boolean property isStudent.
How can I get, using the Hibernate Criteria API, all parent objects that have at least one Child with isStudent = true?
I tried to use the Projection object to count all parents who have at least one Child with the property set correctly, and then return those whose number of lines is greater than zero, for example, in the following code fragment (which doesn’t work):
Criteria criteria = getCurrentSession().createCriteria(Parent.class);
criteria.setProjection(Projections.alias(Projections.rowCount(), "count"))
.add(Restrictions.gt("count", 0)).createCriteria("children")
.add(Restrictions.eq("isStudent", true));
thanks for the help
source
share