I found a slightly different way to resolve this problem by implementing a self join. This saves you having to create a projection list as in the earlier examples. May work for some....
Begin by creating a Detached criteria for the complex query. Add a distinct clause to the query to uniquely identify the @Id values. Next create a criteria that uses this detached criteria to extract the required.
Code:
DetachedCriteria dc = DetachedCriteria.forClass(Employee.class);
dc.createAlias("location", "location");
dc.createAlias("location.dept", "department");
dc.add(
Restrictions.or(
Restrictions.eq("location.id", locationId),
Restrictions.eq("department.name", departmentName)));
dc.setProjection(Projections.distinct(Property.forName("id")));
Code:
Criteria criteria = session().createCriteria(Employee.class);
criteria.add(Property.forName("id").in(dc));
criteria.setMaxResults(maxLength);
criteria.setFirstResult((int)rowNum);