ORDER BY using Criteria API

后端 未结 5 1238
醉酒成梦
醉酒成梦 2020-12-24 00:23

When I write a HQL query

Query q = session.createQuery(\"SELECT cat from Cat as cat ORDER BY cat.mother.kind.value\");
return q.list();

Eve

5条回答
  •  庸人自扰
    2020-12-24 01:02

    You need to create an alias for the mother.kind. You do this like so.

    Criteria c = session.createCriteria(Cat.class);
    c.createAlias("mother.kind", "motherKind");
    c.addOrder(Order.asc("motherKind.value"));
    return c.list();
    

提交回复
热议问题