Skip to content

Document sorting where queries by an association path - #16857

Merged
jdaugherty merged 1 commit into
8.0.xfrom
docs/hibernate7-where-query-association-sort-8.0.x
Nov 4, 2026
Merged

jdaugherty merged 1 commit into
8.0.xfrom
docs/hibernate7-where-query-association-sort-8.0.x

Conversation

@matrei

@matrei matrei commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

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:

// fails because a dynamic alias is used
Pet.where {
    owner.firstName == "Fred"
}.list(sort:"owner.lastName")

With Hibernate 7 this sort works, and WhereQueryWithAssociationSortSpec already 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 of list() to a variable named query.

#16853 fixes the same sorts for Hibernate 5, including paths through more than one association, and updates the Hibernate 5 guide.

Tests

WhereQueryWithAssociationSortSpec for Hibernate 7 checked the sort in one feature, under then: 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:

  • a where query with criteria on club, sorted by club.name ascending and descending, with a sort map, and with chained where calls and fetch: [club: 'join'];
  • sorting by club.id, by an explicit alias, and by club.name in a query without criteria on club;
  • sorting by two properties of club in a query without criteria on club;
  • sorting by team.club.name, a path through more than one association, with criteria on team.club, with criteria on team only, without criteria on either, and through an explicit alias for team.

These pass:

  • all tests of grails-data-hibernate7-core;
  • aggregateViolations.

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-app

testlens-app Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

🚨 TestLens detected 1 failed test 🚨

Test Summary

Tip

Inspect all details with the TestLens CLI: testlens pr 16857

CI / Build Grails-Core (Windows JDK 25 shard 2) > :grails-shell-cli:test

Test Runs Flakiness
SpringApplicationRunnerSpec > ROOT OFF prints #failureMode failures to stderr > ROOT OFF prints launch failures to stderr ❌ 1% 🟡

🏷️ Commit: 8b6e96e
▶️ Tests: 91441 executed
⚪️ Checks: 94/94 completed

Test Failures

SpringApplicationRunnerSpec > 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))
Condition failed with Exception:

runFixture(failureMode, false) == 'verified'
|          |
|          launch
java.lang.AssertionError: Spring application runner fixture timed out after 30 seconds
	at org.grails.cli.command.run.SpringApplicationRunnerSpec.awaitProcess(SpringApplicationRunnerSpec.groovy:85)
	at org.grails.cli.command.run.SpringApplicationRunnerSpec.runFixture(SpringApplicationRunnerSpec.groovy:63)
	at org.grails.cli.command.run.SpringApplicationRunnerSpec.ROOT OFF prints #failureMode failures to stderr(SpringApplicationRunnerSpec.groovy:34)

	at org.grails.cli.command.run.SpringApplicationRunnerSpec.ROOT OFF prints #failureMode failures to stderr(SpringApplicationRunnerSpec.groovy:34)
Caused by: java.lang.AssertionError: Spring application runner fixture timed out after 30 seconds
	at org.grails.cli.command.run.SpringApplicationRunnerSpec.awaitProcess(SpringApplicationRunnerSpec.groovy:85)
	at org.grails.cli.command.run.SpringApplicationRunnerSpec.runFixture(SpringApplicationRunnerSpec.groovy:63)
	... 1 more

Rerun Controls

Select tests to mute in this pull request:

  • SpringApplicationRunnerSpec > ROOT OFF prints #failureMode failures to stderr

Reuse successful test results:

  • ♻️ Only rerun the tests that failed or were muted before

Click the checkbox to trigger a rerun:

  • Rerun jobs

Learn more about TestLens at testlens.app/docs.

@jdaugherty
jdaugherty merged commit b756540 into 8.0.x Nov 4, 2026
94 of 95 checks passed
@jdaugherty
jdaugherty deleted the docs/hibernate7-where-query-association-sort-8.0.x branch November 4, 2026 21:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants