0

我正在尝试调试 n+1 查询问题,并尝试使用 EntityGraphs 来解决它。

说我有以下查询

@Query("select om.organization from OrganizationMember om")

并且组织有一些额外的字段说“属性”

EntityGraph优化会应用于选择吗?

@EntityGraph(attributePaths = {
  "attributes",
})
@Query("select om.organization from OrganizationMember om")

或者我应该这样做吗?

@EntityGraph(attributePaths = {
  "organization.attributes",
})
@Query("select om.organization from OrganizationMember om")
4

1 回答 1

0

做了我的实验,它似乎在from场上。

@EntityGraph(attributePaths = {
  "organization.attributes",
})
@Query("select om.organization from OrganizationMember om")

否则会得到

org.springframework.dao.InvalidDataAccessApiUsageException:无法在此 ManagedType 上找到具有给定名称 [attributes] 的属性 ...

于 2022-02-09T00:57:02.737 回答