Skip to content

Fetch singular associations right away in PostponedFetchRoot - #68

Merged
BalusC merged 1 commit into
developfrom
fix/singular-fetch-not-postponed
Nov 2, 2026
Merged

BalusC merged 1 commit into
developfrom
fix/singular-fetch-not-postponed

Conversation

@BalusC

@BalusC BalusC commented Nov 2, 2026

Copy link
Copy Markdown
Member

PostponedFetchRoot postponed every fetch. Since 82cf971 it is also used on Hibernate when the page has a limit. A fetched @ManyToOne then dropped out of the select list. Ordering on it under DISTINCT, which optional criteria cause, failed on H2 and PostgreSQL with "Order by expression must be in the result list".

PostponedFetchRoot now fetches a singular association with a left fetch join in the paged query, via the new SingularFetch, because it does not multiply rows. Everything else is postponed as before, embeddables included. A postponed fetch nested in a singular association also postpones all its ancestor paths, so that the secondary query can build the fetch joins down to it. Those ancestors are then fetched once more by the secondary query.

  • New IT testPhonePageWithOwnersSortedByOwnerEmailAndOptionalCriteria reproduces the failure. New IT testPhonePageWithOwnerPhonesAndPagination covers a plural fetch nested in a singular one.
  • PostponedFetchTest#rootFetchByAnyOverloadIsPostponed asserted the old contract, so it is replaced by tests for the new one.
  • Locally run on WildFly only. EclipseLink and OpenJPA now also do real singular fetch joins, so check their CI jobs one by one.

#61 has the same origin but is a separate bug: @OneToMany ordering is still skipped under PostponedFetchRoot.

🤖 Generated with Claude Opus 5.5

PostponedFetchRoot postponed every fetch. Since 82cf971 it is also used
on Hibernate when the page has a limit. A fetched @manytoone then
dropped out of the select list, and ordering on it under DISTINCT,
which optional criteria cause, failed on H2 and PostgreSQL with "Order
by expression must be in the result list".

PostponedFetchRoot now fetches a singular association with a left fetch
join in the paged query, via the new SingularFetch, as it does not
multiply rows. Everything else is postponed as before. A postponed
fetch nested in a singular association also postpones all its ancestor
paths, so that the secondary query can build the fetch joins down to
it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@BalusC
BalusC merged commit 750f001 into develop Nov 2, 2026
3 checks passed
@BalusC
BalusC deleted the fix/singular-fetch-not-postponed branch November 2, 2026 20:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant