-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Redundant JOIN Generated with @EntityGraph in Spring Data JPA Query Methods #3717
Comments
Thank you for getting in touch. Spring Data is not in control of the final SQL generated by the persistence provider. The derived query is using the criteria API, the annotated one is based on JPQL. Please try to reproduce the issue using the |
If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed. |
Closing due to lack of requested feedback. If you would like us to look at this issue, please provide the requested information and we will re-open the issue. |
Issue: Redundant
JOIN
Generated with@EntityGraph
in Spring Data JPA Query MethodsWhen using
@EntityGraph
in a repository method that relies on query generation by method name (without explicitly defining a query using@Query
or@NamedQuery
), redundantJOIN
statements are generated if the method name references a relationship that is also included in theattributePaths
of@EntityGraph
.Environment:
Steps to Reproduce:
You can reproduce this issue using this sample project. The project includes two test cases, one of which fails due to the issue.
I captured the generated SQL statements using a Hibernate interceptor and verified the occurrence count of
JOIN
operations.Entities:
Here are the entity definitions:
Repository Methods:
The
EmployeeRepository
contains the following two methods:Generated SQL Queries:
For the first method (
findAllByCompanyEnableIsTrue
), which relies on the method name for query generation, the following SQL is generated:As shown, there is a redundant
JOIN
.However, for the second method (
findAllByCompanyEnableIsTrueUsingQuery
), which uses an explicitly defined query, the generated SQL is:This query avoids the redundant
JOIN
.Expected Behavior:
The query generated for the method using the method name (
findAllByCompanyEnableIsTrue
) should avoid redundantJOIN
statements, similar to the query generated byfindAllByCompanyEnableIsTrueUsingQuery
.Observed Behavior:
Using
@EntityGraph
with query methods generated by method name causes redundantJOIN
operations when a relationship is referenced in both the method name and theattributePaths
of@EntityGraph
.Additional Information:
Please let me know if further clarification or additional examples are needed.
The text was updated successfully, but these errors were encountered: