9
私はJPAの基準を使用するには、以下のHQLを変更しようとしています:CriteriaBuilder.and&CriteriaBuilder.or、how-to?
select distinct d from Department d
left join fetch d.children c
where d.parent is null
and (
d.name like :term
or c.name like :term
)
order by d.name
Department
は子供のSet<Department>
を持っています。
基準は:正しく
and (x = y OR z = y)
:
CriteriaBuilder cb = getEntityManager().getCriteriaBuilder();
CriteriaQuery<Department> c = cb.createQuery(Department.class);
Root<Department> root = c.from(Department.class);
root.fetch("children", JoinType.LEFT);
Path<Department> children = root.join("children", JoinType.LEFT);
c.orderBy(cb.asc(root.get("name")));
c.distinct(true);
c.where(cb.isNull(root.get("parent")));
String param = "%" + "term" + "%";
cb.and(cb.like(root.<String> get("name"), param));
cb.or(cb.like(children.<String> get("name"), param));
TypedQuery<Department> tq = getEntityManager().createQuery(c);
departments = tq.getResultList();
私はそれは少し簡潔な、しかし、HQLは24と基準バージョン28私は私が処理していないと思うが返すことができます知っています。すべてのポインタは非常に高く評価されます。おかげさまで
感謝万人を。 – kmansoor
私もこれを探していたので、ありがとう。 – user75ponic