我遇到了一个简单的问题,不知道如何在联接的实体上调用order by
。本质上,我正在尝试使用JPA Criteria
实现以下内容:
select distinct d from Department d
left join fetch d.children c
left join fetch c.appointments a
where d.parent is null
order by d.name, c.name
我有以下内容:
CriteriaBuilder cb = getEntityManager().getCriteriaBuilder();
CriteriaQuery<Department> c = cb.createQuery(Department.class);
Root<Department> root = c.from(Department.class);
Fetch<Department, Department> childrenFetch = root.fetch(
Department_.children, JoinType.LEFT);
childrenFetch.fetch(Department_.appointments, JoinType.LEFT);
c.orderBy(cb.asc(root.get(Department_.name)));
c.distinct(true);
c.select(root);
c.where(cb.isNull(root.get(Department_.parent)));
如何使用 Criteria API
实现 order by d.name, c.name
?我尝试使用 Expression
和 Path
,但没有成功。
非常感谢您提供任何指示。