Wednesday, 9 July 2014

Hibernate Sort String field after changing to Integer

	Criteria criteria = getCurrentSession().createCriteria(LabOrder.class);

criteria.createAlias("practice", "pract", JoinType.INNER_JOIN);
criteria.createAlias("patient", "pat", JoinType.INNER_JOIN);
criteria.createAlias("labpanel", "panel", JoinType.LEFT_OUTER_JOIN);
criteria.addOrder(new org.hibernate.criterion.Order("orderNo", true) {
@Override
public String toSqlString(Criteria criteria,
CriteriaQuery criteriaQuery) throws HibernateException {
return "cast(orderNo as UNSIGNED) desc";
}
});

2 comments: