return this.getHibernateTemplate().execute(new HibernateCallback<Long>() {
@Override
public Long doInHibernate(Session session) throws HibernateException, SQLException {
CriteriaImpl criteria = (CriteriaImpl)detachedCriteria.getExecutableCriteria(session);
for (Iterator<?> iterator = criteria.iterateOrderings(); iterator.hasNext();) {
iterator.next();
iterator.remove();
}
if (criteria.getMaxResults() != null) {
criteria.setMaxResults(Integer.MAX_VALUE);