| Following criteria produces invalid sql on some db platforms. First, the entity Foo.class, then criteria that creates sql grammar exception below: @Entity @Table(name = "FOO") public class Foo { @Id private Long fooId; private String name; } Then, the criteria in question: Criteria criteria = getSessionFactory().getCurrentSession().createCriteria(Foo.class); criteria.setProjection(Projections.projectionList() .add(Projections.alias(Projections.max("name"), "sortProperty")) .add(Projections.groupProperty("fooId").as("id"))) .addOrder(Order.asc("sortProperty").ignoreCase()); Results in following sql: select max(this_.NAME) as y0_, this_.FOO_ID as y1_ from FOO this_ group by this_.FOO_ID order by lower(y0_) asc; In Oracle, this case-insensitive query runs fine. But other db platforms (e.g., H2 and Postgres) do not support an alias in the lower() function. |