Skip to content
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

Empty attributePaths on @EntityGraph produces exception #3682

Closed
lbruun opened this issue Nov 17, 2024 · 1 comment
Closed

Empty attributePaths on @EntityGraph produces exception #3682

lbruun opened this issue Nov 17, 2024 · 1 comment
Assignees
Labels
type: bug A general bug

Comments

@lbruun
Copy link

lbruun commented Nov 17, 2024

From how I understand the JPA specs there would be nothing wrong with the following Spring Data JPA annotation:

  @EntityGraph(attributePaths = {}) // Purpose: exclude all EAGER relations

The purpose would be to create a query using an entity graph with no attributes added. Perfectly legal in JPA. (and indeed a valid use case)

However, with Spring Data JPA this is not possible as class JpaEntityGraph uses the following (flawed?) logic to distinguish between dynamic and static named graphs:

public boolean isAdHocEntityGraph() {
    return !attributePaths.isEmpty();
}

Therefore, the query result in an exception :

java.lang.IllegalArgumentException: The given JpaEntityGraph [...] is not dynamic

This is wrong. The entity graph is indeed dynamic. It just happens to be an entity graph with no attributes added.

Another way to phrase the problem is that putting this on a query method in a Spring Data repo:

  @EntityGraph(attributePaths = {}) 

should NOT result in an exception, but should result in a query being performed using an JPA entity graph with no attributes added. Alternatively, please provide another way to achieve the goal.

Thanks.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Nov 17, 2024
@mp911de mp911de assigned mp911de and christophstrobl and unassigned mp911de Nov 18, 2024
@christophstrobl
Copy link
Member

Thank you for the heads up @lbruun. True, you could have a entity graph without any attributes.
Let me see what we can do to lift the existing restriction.

@christophstrobl christophstrobl added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged labels Nov 19, 2024
@christophstrobl christophstrobl changed the title Bug: Empty attributePaths on @EntityGraph produces exception Empty attributePaths on @EntityGraph produces exception Nov 19, 2024
@mp911de mp911de added type: bug A general bug and removed type: bug A general bug labels Nov 21, 2024
@mp911de mp911de added this to the 3.4.1 (2024.1.1) milestone Nov 21, 2024
mp911de pushed a commit that referenced this issue Nov 21, 2024
An EntityGraph without attributes is valid. Therefore it is not possible to determine if a given JpaEntityGraph is a dynamic one just by looking at the attributes alone.

Original pull request: #3684
See #3682
mp911de added a commit that referenced this issue Nov 21, 2024
Remove JPA 2.1 guards as we require JPA 3.x. Refine API to reduce nullability.

Original pull request: #3684
See #3682
mp911de pushed a commit that referenced this issue Nov 21, 2024
This commit removes a check preventing EntityGraphs from being created for JpaEntityGraphs without attributes.

Original pull request: #3684
Closes #3682
mp911de pushed a commit that referenced this issue Nov 21, 2024
An EntityGraph without attributes is valid. Therefore it is not possible to determine if a given JpaEntityGraph is a dynamic one just by looking at the attributes alone.

Original pull request: #3684
See #3682
mp911de added a commit that referenced this issue Nov 21, 2024
Remove JPA 2.1 guards as we require JPA 3.x. Refine API to reduce nullability.

Original pull request: #3684
See #3682
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug A general bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants