📜  JPA 休眠左连接 - 任何代码示例

📅  最后修改于: 2022-03-11 14:56:40.588000             🧑  作者: Mango

代码示例1
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery cq = cb.createTupleQuery();
Root root = cq.from(Author.class);
Join book = root.join(Author_.BOOKS, JoinType.LEFT);
cq.multiselect(root, book);
 
ParameterExpression pLastName = cb.parameter(String.class);
cq.where(cb.equal(root.get(Author_.LAST_NAME), pLastName));
 
TypedQuery q = em.createQuery(cq);
q.setParameter(pLastName, "Janssen");
List authorBooks = q.getResultList();