我在服务器日志中收到警告 “firstResult/maxResults specified with collection fetch; applying in memory!” .但是一切正常。但我不想要这个警告。
我的代码是
public employee find(int id) {
return (employee) getEntityManager().createQuery(QUERY).setParameter("id", id).getSingleResult();
}
我的查询是
QUERY = "from employee as emp left join fetch emp.salary left join fetch emp.department where emp.id = :id"
原文由 Gnik 发布,翻译遵循 CC BY-SA 4.0 许可协议
此警告的原因是当使用 fetch join 时,结果集中的顺序仅由所选实体的 ID 定义(而不是由 join fetched)。
如果这种内存排序导致问题,请不要将 firsResult/maxResults 与 JOIN FETCH 一起使用。