Skip to content

Instantly share code, notes, and snippets.

@ozkansari
Created December 30, 2013 11:19
public List<Mother> find(String aProperty){
Session session = getSession(); // Create hibernate session
Criteria motherCrit = s.createCriteria(Mother.class);
// Create sub query
DetachedCriteria childListCrit = DetachedCriteria.forClass(Child.class);
childListCrit.add(Restrictions.eq("aProperty", aProperty));
childListCrit.setProjection(Projections.distinct(Projections.property("mother.id")));
motherCrit.add(Subqueries.propertyIn("id", childListCrit));
return motherCrit.list();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment