Sono bloccato con un semplice problema; lottando su come chiamare order by
su un'entità join
edita. In sostanza sto cercando di raggiungere i seguenti obiettivi con JPA Criteria
:Criteri JPA API di query e ordine di due colonne
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
Ho il seguente:
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)));
Come realizzare order by d.name, c.name
con Criteria API
? Ho provato con Expression, Path ma non ha funzionato. Qualsiasi suggerimento sarà molto apprezzato.
Come è descritta una risposta all'autore del problema? – ByeBye
Perché pensi che non sia così? Voleva sapere come ordinare per più proprietà. La mia risposta contiene come farlo ... Mi manca qualcosa? – Adamsan
Perché non funzionerà con distinto e ordinamento per proprietà dalla tabella di join – ByeBye