public final Map<String, Object> findByMap( final Map<String, Object> params, int page, int rows, String order, boolean asc) throws HibernateException { Criteria criteria = getSession().createCriteria(clazz); Long total; if (null != params) criteria.add(Restrictions.allEq(params)); total = (Long) criteria.setProjection(Projections.rowCount()).uniqueResult(); criteria.setProjection(null).setResultTransformer(Criteria.ROOT_ENTITY); if (page > 0 && rows > 0) criteria.setFirstResult((page - 1) * rows).setMaxResults(rows); if (null != order) { if (asc) criteria.addOrder(Order.asc(order)); else criteria.addOrder(Order.desc(order)); } Map<String, Object> result = new HashMap<String, Object>(); result.put("total", total); result.put("rows", (List<T>) criteria.list()); return result; }