spring-projects / spring-projects/spring-data-jpa

Data eager loaded by @EntityGraph is affected by where clause that filters on same relationship [DATAJPA-1746]

Open
#2,040 0 comments 3 reactions 1 assignee View on GitHub

@schauder is already working on this.

Since Dec 30, 2020.

type: bug
Dominant language
Java
Stars
3.3k
Forks
1.6k
PR merge metrics
No merged PRs in 30d

Description

Jonathon Henderson opened DATAJPA-1746 and commented

When using the @EntityGraph annotation to eager load a relation during a query, a "where" clause applied to that same relation causes the eagerly loaded relation data to also be affected by that where clause.

e.g. Given an Article and Tag with a many-to-many relationship between them. A method on the ArticleRepository named findAllByTagsIn, annotated with @EntityGraph(attributePaths = {"tags"}) would result in a query that properly filters articles to only retrieve those that have the given tags. However, the eagerly loaded tags would only include those that were passed to the method when it was called, rather than all of the tags associated with each article.

See the StackOverflow link for more details


Affects: 2.3.1 (Neumann SR1)

Reference URL: https://stackoverflow.com/questions/62434684/jpa-entity-graph-eager-loading-affected-by-where-clause

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.