I'd suggest the following:
Code:
StringBuffer hql = new StringBuffer();
hql.append("from TblDocumentos as model where model.").append(property).append("=?");
Query query = session.createQuery(hql.toString());
query.setParameter(0, value);
results = query.setFirstResult(offset * limitPage).setMaxResults(limitPage).list();
hql.insert(0, "select count(*) ");
query = session.createQuery(hql.toString());
query.setParameter(0, value);
Number n = (Number) query.uniqueResult();
long count = n != null? n.longValue(): 0;
Yes, query.uniqueResult() may return null. It's the case when your statement does not match any rows.