我遇到了一个简单的问题;苦苦挣扎如何order by
在join
ed 实体上调用。本质上,我试图通过以下方式实现以下目标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)));
如何order by d.name, c.name
实现Criteria API
?我尝试了 Expression, Path 但没有用。任何指针将不胜感激。