Criteria c = getSession().createCriteria(User.class); if (groupId != null) { c.createCriteria("groups", "g"); c.add(Restrictions.eq("g.id", groupId)); }
Criteria c = getUsersCriteria(groupId);
    public List loadUsersByPage(Integer groupId, int firstRow, int pageSize, String orderBy, boolean orderAscending) {        Criteria c = getSession().createCriteria(User.class);        if (groupId != null) {            c.createCriteria("groups", "g");            c.add(Restrictions.eq("g.id", groupId));        }        c.setFirstResult(firstRow);        c.setMaxResults(pageSize);        Order order = orderAscending ? Order.asc(orderBy) : Order.desc(orderBy);        c.addOrder(order);        List users = c.list();        return users;    }