well, it's not that simpile
I mean with a GIVEN criteria
here is my current code, i wonder if there would be a better solution.
Code:
private int getRecordCount(DetachedCriteria criteria) {
Criteria c = criteria.getExecutableCriteria(getSession());
CriteriaImpl ci = (CriteriaImpl) c;
int count = 0;
try {
Object orderEntries = BeanUtils
.forceGetProperty(ci, "orderEntries");
BeanUtils.forceSetProperty(ci, "orderEntries", new ArrayList());
Projection proj = ci.getProjection();
if (proj == null) {
Object obj = ci.setProjection(Projections.rowCount())
.uniqueResult();
count = ((Number) obj).intValue();
} else {
count = ci.list().size();
}
BeanUtils.forceSetProperty(ci, "orderEntries", orderEntries);
ci.setProjection(proj);
} catch (NoSuchFieldException e) {
throw new InternalError(e.getMessage());
}
return count;
}