Case-insensitive ordering using Hibernate Criteria

simon picture simon · Nov 25, 2011 · Viewed 9.3k times · Source

I have a query created with Hibernate Criteria like this:


Criteria criteria = db.getSession().createCriteria(Vendor.class);
criteria.addOrder(Property.forName("shortName").asc());
List<Vendor> vendorList = criteria.list();

I would like the ordering to be case-insensitive, equivalent to the HQL query


FROM Vendor ve ORDER BY lower(ve.shortName)

How can I achieve this using Hibernate Criteria?

Answer

erimerturk picture erimerturk · Nov 25, 2011
criteria.addOrder(Order.asc("shortName").ignoreCase());