Try:
Information about the table): Category (id, name, desc, parentId, active)
DetachedCriteria subCriteria = DetachedCriteria .forClass(Category.class); subCriteria.add(Restrictions.isNull("parent")); subCriteria.add(Restrictions.eq("active", Boolean.TRUE)); subCriteria.add(Restrictions.eq("name", categoryName)); subCriteria.setProjection(Projections.property("id")); Criteria criteria = getSession().createCriteria(Category.class); criteria.add(Restrictions.eq("active", Boolean.TRUE)); criteria.add(Subqueries.propertyEq("parent", subCriteria));
It will generate a request like:
select * from Category this_ where this_.active = 1 and this_.parentId = (Select this0_.id as y0 from Category this0__ where this0_.parentId is null and this0_.active = 1 and this0 __. name = 'Health Plan')
Good luck
-Rohtash Singh
source share