当我编写HQL查询时
Query q = session.createQuery("SELECT cat from Cat as cat ORDER BY cat.mother.kind.value"); return q.list();
一切安好。但是,当我编写标准时
Criteria c = session.createCriteria(Cat.class); c.addOrder(Order.asc("mother.kind.value")); return c.list();
我有一个例外 org.hibernate.QueryException: could not resolve property: kind.value of: my.sample.data.entities.Cat
org.hibernate.QueryException: could not resolve property: kind.value of: my.sample.data.entities.Cat
如果我想使用“标准和顺序”,我应该如何表达我的“顺序”?
您需要为创建别名mother.kind。你是这样做的。
mother.kind
Criteria c = session.createCriteria(Cat.class); c.createAlias("mother.kind", "motherKind"); c.addOrder(Order.asc("motherKind.value")); return c.list();