從JPA規範剖面中6.5.4
CriteriaQuery<Department> q = cb.createQuery(Department.class);
Root<Department> d = q.from(Department.class);
d.fetch(Department_.employees, JoinType.LEFT);
q.where(cb.equal(d.get(Department_.deptno), 1)).select(d);
此查詢等同於以下Java持久化查詢語言查詢:
SELECT d
FROM Department d LEFT JOIN FETCH d.employees
WHERE d.deptno = 1
這是我做沒有取
CriteriaQuery<Department> q = cb.createQuery(Department.class);
Root<Department> dept = q.from(Department.class);
Join<Department,Employee> emp = d.join(Department_.employees);
q.where(cb.equal(emp.get(Employee_.name),"edalorzo"));
Fetch是一種連接,所以我想你也可以嘗試一下。