sql - 我需要使用 join fetch,但它会导致 "query specified join

我有以下查询:

@Query("SELECT new de.projectemployee.ProjectEmployee(employee) " +
       "FROM ProjectEmployee projectEmployee JOIN FETCH projectEmployee.employee employee " +
       "WHERE projectEmployee.project.id = :id")
List<ProjectEmployee> findInOneRequestByProjectId(@Param("id") long id);

我收到以下错误:

org.hibernate.QueryException: query specified join fetching, but the owner of the fetched association was not present in the select list

正如许多解决方案所建议的那样,我可以将 JOIN FETCH 替换为 JOIN。但是这个解决方案的问题是它会导致 n+1 个请求。有没有其他方法可以修复错误?

最佳答案

Fetch 用于填充对象中的延迟加载字段,这里没有用。只需从您的查询中删除 FETCH 即可。

关于sql - 我需要使用 join fetch,但它会导致 "query specified join fetching, but the owner of the fetched association was not present in the select list",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59686211/

相关文章:

python - pytest:带参数的自定义标记

javascript - 如何使用 JavaScript 观察 an 元素的 scrollWidth

json - Spring webflux Netty : How to expose proto

visual-studio - 强制 Visual Studio 从光标处查找

google-chrome - 如何在 .Net framework 4.0.30319 中设置 H

google-cloud-platform - 如何部署使用google cloud build和S

wpf - 如何将新的 WPF UserControl 添加到我的 .NetCore 3.1 应用程

javascript - 错误 : Objects are not valid as a React

django - this.$apollo 始终未定义

javascript - 如何从 HTML 中的颜色选择器中删除 "other..."选项?