gpt4 book ai didi

sql - 我需要使用 join fetch,但它会导致 "query specified join fetching, but the owner of the fetched association was not present in the select list"

转载 作者:行者123 更新时间:2023-12-05 08:11:21 35 4
gpt4 key购买 nike

我有以下查询:

@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/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com