Skip to content

Hibernate 7: the fetch mode join of list() keeps the instances whose association is null or empty - #16898

Merged
borinquenkid merged 1 commit into
8.0.xfrom
fix/h7-list-fetch-join-keeps-null-8.0.x
Nov 9, 2026
Merged

borinquenkid merged 1 commit into
8.0.xfrom
fix/h7-list-fetch-join-keeps-null-8.0.x

Conversation

@borinquenkid

Copy link
Copy Markdown
Member

Team.list(fetch: [club: 'join']) built join fetch, an inner join, so it left out the teams without a club. A where query, a dynamic finder and a criteria query with the same fetch return every team. list() and a paged list now build left join fetch, so the fetch mode join fetches and never filters. A join type (JoinType.INNER) stays the way to ask for the filter.

This is the Hibernate 7 half of the question jdaugherty raised on #16853; the Hibernate 5 half is on that PR (1e475136f4). Behavior is the same on both after the two.

ListFetchJoinNullSpec runs the fetch mode join on a nullable association and on an empty collection for list, a paged list, a where query and a dynamic finder; the list cases fail without the change. The H7 core suite passes.

…in and keeps the instances whose association is null or empty

list() and a paged list built 'join fetch', an inner join, so Team.list(fetch: [club: 'join']) left out the teams without a club, while a where query and a dynamic finder returned every team. It now builds 'left join fetch', as the join type LEFT does; only a join type asks for the instances to be left out. ListFetchJoinNullSpec runs the fetch mode join on an association that can be null and on a collection that can be empty for list, a paged list, a where query and a dynamic finder; the list cases fail without the change.

Claude-Session: https://claude.ai/code/session_01Dmki4RzWwreEC2GkkyFnvL
Copilot AI balanced review requested due to automatic review settings November 8, 2026 22:15

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@jamesfredley jamesfredley left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A fetch join of list() now keeps the instances whose association is null or empty.

@borinquenkid
borinquenkid merged commit 16a3093 into 8.0.x Nov 9, 2026
49 checks passed
borinquenkid added a commit that referenced this pull request Nov 9, 2026
The fetch mode join of a list query is a left join (#16898), also where the query sorts through the fetched association and the fetch shares its alias. The upgrade guide entry about sorting by an association follows the entry about exception mappings.

Claude-Session: https://claude.ai/code/session_01Dmki4RzWwreEC2GkkyFnvL
@matrei

matrei commented Nov 12, 2026

Copy link
Copy Markdown
Contributor

This changes which rows list() returns, and 8.0.0 shipped with the old behavior. On 8.0.0, Team.list(fetch: [club: 'join']) leaves out the teams without a club, and Team.list(fetch: [players: 'join']) leaves out the teams without players. With this change both return every team, so 8.0.1 would return more rows than 8.0.0 for the same call. An app on 8.0.0 can depend on the old result, and there's no upgrade note for it.

Hibernate 5 still leaves those rows out on 8.0.x, because its list() applies the fetch mode as queryRoot.join(associationName), an inner join that doesn't fetch. The Hibernate 5 half is 1e475136f4 on #16853, and I've proposed moving that part of #16853 to 9.0.x. If we do that, 8.0.1 would ship with Hibernate 5 and Hibernate 7 returning different rows for the same call.

I agree the new behavior is the right one: a fetch mode should decide how an association is loaded, not which rows come back. But like the Hibernate 5 half, it's a behavior change, and since Grails 8 has shipped, it belongs in Grails 9.

I'd like to revert it on 8.0.x before 8.0.1 is released, and keep it on 9.0.x when the revert is merged up, so it lands in Grails 9 together with the Hibernate 5 half. If you'd rather keep it in 8.0.1, it needs an upgrade note at least, and the note should say that Hibernate 5 still leaves the rows out.

@borinquenkid

Copy link
Copy Markdown
Member Author

Filed #16939 for this, with a revert on 8.0.x (PR coming) that keeps the change on 9.0.x.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

4 participants