我可以通过属于提取的字段订购标准查询吗?

时间:2014-08-14 01:18:42

标签: jpa criteria-api

按属于加入的字段排序效果很好:

CriteriaBuilder builder = em.getCriteriaBuilder();
Root root = criteria.from(Employee.class);
Join joinPerson = root.join("person");

criteria.orderBy(builder.asc(joinPerson.get("lastName")));

如何通过获取

来解决类似问题
CriteriaBuilder builder = em.getCriteriaBuilder();
Root root = criteria.from(Employee.class);
Fetch fetchPerson = root.fetch("person");

criteria.orderBy(builder.asc(fetchPerson.????));

1 个答案:

答案 0 :(得分:1)

将您的抓取功能转换为路径,例如:

    Path fetchAsPath = (Path) root.fetch("person");

    fetchAsPath.get("lastName");