However, if i use Criteria.DISTINCT_ROOT_ENTITY),
it causes error when i use these for paging purpose
criteria.setFirstResult(offset);
criteria.setMaxResults(size);
any idea? thx
thatmikewilliams wrote:
This was as close as I could get:
Code:
Criteria c = s.createCriteria(User.class)
.createAlias("office", "o")
.add(Restrictions.ilike("staffNo", "%staffNo%"))
.add(Restrictions.ilike("badgeNo", "%badgeNo%"))
.add(Restrictions.or(
Restrictions.ilike("firstName", "%name%"),
Restrictions.ilike("lastName", "%name%")))
.createCriteria("userRoles")
.createCriteria("systemRole")
.add(Restrictions.eq("roleId", new Long(1)))
.add(Restrictions.eq("o.officeId", new Long(1)))
.addOrder(Order.asc("o.officeName"))
.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY)
;
Differences:
- distinct applied in java instead of in the database
- collections lazy populated BUT will contain all items