Skip to content

Add EntityGraphHint query method parameter - #4285

Open
yeomin4242 wants to merge 3 commits into
spring-projects:mainfrom
yeomin4242:gh-4175-entity-graph-parameter
Open

Add EntityGraphHint query method parameter#4285
yeomin4242 wants to merge 3 commits into
spring-projects:mainfrom
yeomin4242:gh-4175-entity-graph-parameter

Conversation

@yeomin4242

Copy link
Copy Markdown

Repository query methods can now accept EntityGraphHint to select an entity graph per invocation.

The hint can be created from type-safe property paths, named entity graphs, or a JPA EntityGraph instance. We treat the hint as a special parameter so it is excluded from query binding and apply it for runtime and AOT query creation. If the argument is null, query creation falls back to the declared @EntityGraph metadata.

Includes unit and integration tests for parameter discovery, runtime query creation, repository execution, and AOT query generation.

Closes #4175

  • You have read the Spring Data contribution guidelines.
  • You use the code formatters provided here and have them applied to your changes. Don’t submit any formatting related changes.
  • You submit test cases (unit or integration tests) that back your changes.
  • You added yourself as author in the headers of the classes you touched. Amend the date range in the Apache license header if needed. For new types, add the license header (copy from another file and set the current year only).

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Jun 16, 2026
@yeomin4242
yeomin4242 force-pushed the gh-4175-entity-graph-parameter branch from 3d4594c to 89181cd Compare June 16, 2026 10:57
Repository query methods can now accept EntityGraphHint to choose an entity graph per invocation from typed property paths, named entity graphs, or a JPA EntityGraph instance. The hint is treated as a special parameter and applied by runtime and AOT query creation.

Closes spring-projects#4175
Signed-off-by: YeongJae Min <whereismysejong@naver.com>
@yeomin4242
yeomin4242 force-pushed the gh-4175-entity-graph-parameter branch from 89181cd to 8788976 Compare June 16, 2026 11:59
@yeomin4242
yeomin4242 marked this pull request as ready for review June 17, 2026 06:25
@mp911de mp911de self-assigned this Jun 29, 2026
@mp911de mp911de added type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged labels Jun 30, 2026
@jewoodev

jewoodev commented Jul 4, 2026

Copy link
Copy Markdown
Contributor

One precedence case seems worth pinning down with a regression test: if a query method declares @EntityGraph and receives a non-null EntityGraphHint, the parameter hint should override the declared graph.

The implementation currently does that, while the tests cover the hint-only path and the null fallback path. Adding a runtime/AOT test for the non-null override case would make the new invocation-level contract explicit.

@yeomin4242

Copy link
Copy Markdown
Author

One precedence case seems worth pinning down with a regression test: if a query method declares @EntityGraph and receives a non-null EntityGraphHint, the parameter hint should override the declared graph.

The implementation currently does that, while the tests cover the hint-only path and the null fallback path. Adding a runtime/AOT test for the non-null override case would make the new invocation-level contract explicit.

@jewoodev Thanks!

I added regression tests for this in both the runtime and AOT paths. The tests invoke a method that declares @EntityGraph with a non-null EntityGraphHint for a different association, then assert that the parameter hint takes effect and the declared graph does not.

That should make the intended precedence explicit: non-null EntityGraphHint overrides the declared graph, while null continues to fall back to @EntityGraph.

Add runtime and AOT coverage for query methods that declare @EntityGraph and receive a non-null EntityGraphHint, verifying that the invocation-level hint takes precedence over the declared graph.

Related spring-projects#4175

Signed-off-by: YeongJae Min <whereismysejong@naver.com>
@yeomin4242
yeomin4242 force-pushed the gh-4175-entity-graph-parameter branch from 523621a to 1de59ae Compare July 7, 2026 07:30
Keep the existing named-graph null fallback fixture intact and add a separate explicit attribute-path method for the override test, so the override assertion does not depend on the contents of a named graph.

Related spring-projects#4175

Signed-off-by: YeongJae Min <whereismysejong@naver.com>
@yeomin4242
yeomin4242 force-pushed the gh-4175-entity-graph-parameter branch from 1de59ae to c33c53e Compare July 7, 2026 07:34
@mp911de
mp911de force-pushed the main branch 2 times, most recently from 4887543 to c43320e Compare August 5, 2026 14:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type: enhancement A general enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Consider EntityGraph argument for query methods

4 participants