我有3个实体,我想使用JPA CriteriaBuilder进行以下SQL查询。
SELECT *
FROM record as a
JOIN record_management as b ON (a.id_supervisor = b.id OR a.id_manager = b.id)
JOIN user as c ON(b.id_user = c.id)
WHERE a.id_company = 1
我尝试编写以下代码,但无法编写第二个JOIN(joinRM)
CriteriaBuilder cb = ...
CriteriaQuery<Record> query = ...
Root<Record> root = query.from(Record.class);
Join<Record, RecordManagement> joinRM = ??????
Join<RecordManagement, User> joinUser = root.join("id_user");
Predicate p1 = cb.equal(root.get("id_company"), 1);
query.select(root);
query.where(p1);
return entityManager.createQuery(query).getResultList();
该查询如何?