Despite the fact that the topic is old and the problem may be solved, I will send a solution. Perhaps this will be useful in the future for someone.
criteria.addOrder(new org.hibernate.criterion.Order("anystring", true) {
@Override
public String toSqlString(Criteria criteria, CriteriaQuery criteriaQuery) throws HibernateException {
return "cast(id as int)";
}
});
source
share