Repository navigation
Document sorting where queries by an association path - #16857
Merged
jdaugherty merged 1 commit intoNov 4, 2026
Merged
Conversation
With Hibernate 7, a where query can be sorted by a property of an associated entity, also when the query has criteria on the association and through more than one association. The guide said that this sort fails and that an explicit alias is required.
🚨 TestLens detected 1 failed test 🚨Test SummaryTip Inspect all details with the TestLens CLI: CI / Build Grails-Core (Windows JDK 25 shard 2) > :grails-shell-cli:test
🏷️ Commit: 8b6e96e Test FailuresSpringApplicationRunnerSpec > ROOT OFF prints #failureMode failures to stderr > ROOT OFF prints launch failures to stderr (:grails-shell-cli:test in CI / Build Grails-Core (Windows JDK 25 shard 2))Rerun ControlsSelect tests to mute in this pull request:
Reuse successful test results:
Click the checkbox to trigger a rerun:
Learn more about TestLens at testlens.app/docs. |
jdaugherty
deleted the
docs/hibernate7-where-query-association-sort-8.0.x
branch
November 4, 2026 21:32
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
The "Query Aliases and Sorting" section of the GORM for Hibernate 7 guide said that sorting a where query by a property of an association fails when the query has criteria on the same association, and that an explicit alias is required:
With Hibernate 7 this sort works, and
WhereQueryWithAssociationSortSpecalready expected it to. The section now shows sorting by the association path, notes that the path can go through more than one association, and keeps the explicit alias as an alternative. Its alias example no longer assigns the result oflist()to a variable namedquery.#16853 fixes the same sorts for Hibernate 5, including paths through more than one association, and updates the Hibernate 5 guide.
Tests
WhereQueryWithAssociationSortSpecfor Hibernate 7 checked the sort in one feature, underthen:labels saying that an exception is thrown, and with a SQL listing in a comment that no longer matched the query. It now has the same cases as the Hibernate 5 spec in #16853:club, sorted byclub.nameascending and descending, with a sort map, and with chainedwherecalls andfetch: [club: 'join'];club.id, by an explicit alias, and byclub.namein a query without criteria onclub;clubin a query without criteria onclub;team.club.name, a path through more than one association, with criteria onteam.club, with criteria onteamonly, without criteria on either, and through an explicit alias forteam.These pass:
grails-data-hibernate7-core;aggregateViolations.