I have a one-to-many association and want to be able to filter the children (by searching on them) and still be able to iterate over the parents with only the appropriate children present.
So basically I have this. Three kids aged 8, 9, and 11.
Code:
Criteria criteria = session.createCriteria(Parent.class);
criteria.createCriteria("children").add(Expression.gt("age", new Integer(10)));
return criteria.list();
If I execute the SQL it generates, there is only one record returned, which is correct and what I want. But if I iterate through the returned Parent object, it outputs all three kids (and I know why it does, it doesn't care about my filtering).
Is there a way to prevent the parent object from loading the children that do not match the criteria?
I'm using Spring 2.5 and Hibernate Core 3.2.6.ga