Skip to content

fix(datamapping): read a sort key through the alias of a detached criteria that has the name of a property - #17308

Merged
jdaugherty merged 4 commits into
apache:8.0.xfrom
jdaugherty:fix/sort-validation-root-alias
Dec 3, 2026
Merged

jdaugherty merged 4 commits into
apache:8.0.xfrom
jdaugherty:fix/sort-validation-root-alias

Conversation

@jdaugherty

@jdaugherty jdaugherty commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor

Description

Grails 8 checks the sort argument of list, count and get of a detached criteria, and each key of a map of sort properties, against the properties of the queried class (upgrade note 60 of Grails 8.0). That check does not know the alias that a detached criteria can give the queried class, as in new DetachedCriteria(Book, 'author').

The merge of 7.2.x into 8.0.x (482fbed) brought the sort through that alias from Grails 7.0.18 (#17073). With GORM for Hibernate 5, a sort that starts with the alias sorts by the rest of its path, and when the alias has the name of a property, a key that is not a path from the queried class is read through the alias: author.author.name sorts by the name of the author for new DetachedCriteria(Book, 'author'). The check rejects such a key in the sort argument and in a sort map with Invalid sort property, while the same key given with sort('author.author.name') sorts. On 8.0.x at 482fbed, ten rows of UndefinedAliasSortSpec fail for that reason, in that spec and in RootAliasSortLegacySpec, which runs it with grails.gorm.leftJoinAssociationSort disabled, 20 failures in all:

  • a root alias named #alias is used when the path does not resolve through a property: club.club.name for the alias club, and name.name for the alias name (2 rows).
  • a nested LEFT sort keeps an empty collection with root alias #rootAlias ..., for the alias players, the fetch players.players.team and the sort players.players.team.name, as the sort argument and as a sort map, with and without pagination (4 rows).
  • a LEFT #request of #joinPath keeps a book whose author has no publisher with root alias author ..., for author.author.publisher and the sort author.author.publisher.name as the sort argument, with join and with fetch, with and without pagination (4 rows).

This pull request makes the check follow the alias where it rejected such a key. A detached criteria whose query is given its alias passes it to the check, through a new overload of DynamicFinder.populateArgumentsForCriteria. When the alias is also the name of a property of the queried class, a key that starts with it is read as a path from the queried class first, so author.name keeps its meaning for the alias author, and only when it is not one is the alias stripped, once, and the rest checked as a path from the queried class, which is how the query reads the key. Every other key, including one that starts with an alias that is not the name of a property, is checked exactly as before. With it, the ten rows pass.

With three teams, United First of the club United, Arsenal First of the club Arsenal, and Nomads, which has no club:

new DetachedCriteria(Team, alias), with GORM for Hibernate 5 8.0.x (482fbed) This pull request
alias club: list(sort: 'club.club.name'), also as a sort map, and get(sort: 'club.club.name', max: 1) Invalid sort property Arsenal First, United First, as sort('club.club.name') gives; get gives Arsenal First
alias club: count(sort: 'club.club.name') Invalid sort property 2
alias name: list(sort: 'name.name') and count(sort: 'name.name') Invalid sort property Arsenal First, Nomads, United First, and 3
alias t: list(sort: 't.unknown') and list(sort: 't.club.unknown') QueryException: could not resolve property, from Hibernate the same
alias t: count(sort: 't.unknown'), also as a sort map, and count(sort: 't.club.unknown') 3 and 2 the same
alias club: list(sort: 'club.name'); alias t: list(sort: 't.name') sorts the same
alias club: club.club.unknown; alias name: name.unknown Invalid sort property the same
no alias: club.club.name Invalid sort property the same
alias t: t.name desc, t..name or t. Invalid sort property the same
  • With GORM for Hibernate 7, list and get reject every sort that starts with the alias of the queried class, with Invalid sort property, before and after this change. Hibernate 7: resolve the root alias in detached-criteria sorts and restrictions #17167 tracks sorting through that alias with Hibernate 7. count does not sort, so it now accepts a key that resolves through an alias with the name of a property: new DetachedCriteria(Team, 'club').count(sort: 'club.club.name') was Invalid sort property and is 2, and new DetachedCriteria(Team, 'name').count(sort: 'name.name') is 3. Its other counts are the same as on 8.0.x, such as 3 for count(sort: 't.club.unknown').
  • A datastore whose session does not give a query the alias of the criteria, such as GORM for MongoDB, checks the key as before.
  • A sort given with sort() is not checked, as before.

Results that change

  • With GORM for Hibernate 5, a key in the sort argument or a sort map that resolves only through an alias of the detached criteria with the name of a property, such as author.author.name for the alias author, sorts by the rest of its path in list and get, and count returns the count, where all three threw Invalid sort property. With GORM for Hibernate 7, count returns the count, and list and get still throw.
  • No call that returned results or a count on 8.0.x returns other results or another count: the calls that change are calls that threw. There is no setting.

The 8.0.1 note on the sort through the alias of the queried class in the upgrade guide says that the check no longer rejects such a key, and the upgrade skill has the same in its 8.0.1 part.

Contributor Checklist

Please review the following checklist before submitting your pull request. Pull requests that do not meet these requirements may be closed without review.

Issue and Scope

  • This PR is linked to an existing issue that has been acknowledged or approved by the project team. If no approved issue exists, please give background on why this change is necessary. Tickets are preferred for release change log history.
  • This PR addresses the complete scope of the linked issue. Partial implementations or unfinished work should not be submitted for review.
  • This PR contains a single, focused change. Unrelated changes should be submitted as separate pull requests.
  • This PR targets the correct branch for the type of change (see Choosing the Branch):
    • Maintenance branches, whose minor version has been released and that still get patch releases (e.g., 7.0.x, 7.2.x, 8.0.x): Bug fixes only, released as the next patch version. No new features or API changes. A bug fix targets the oldest release branch that has the bug and still gets releases, and is merged up.
    • Next minor branch, until its minor version is released (e.g., 8.1.x before 8.1.0): New features are welcome, but breaking existing APIs must be avoided.
    • Next major branch, until its major version is released (e.g., 9.0.x before 9.0.0): Reserved for major changes. Breaking API changes are permitted.
  • If this PR changes a result, it follows Fixes That Change a Result. A result is what a call that works today returns, stores, renders, binds or maps to, and a fix that makes such a call throw changes one too.
    • The description says which results change, how to get the old ones, and whether the fix needs a setting, and why.
    • The release notes and the upgrade guide section of the release that carries it have a note, and the upgrade skill (grails-skills/upgrade/skills/grails-upgrade/SKILL.md) has the same entry.
    • A setting it adds has a row on the Compatibility Settings page, and an issue for each later step: turning it on and removing it.
    • On a maintenance branch or the next minor branch, it waits for two approving reviews.

Code Quality

  • I have added or updated tests that cover the changes introduced in this PR. All code contributions are expected to include appropriate test coverage.
  • I have verified that all existing tests pass by running ./gradlew build --rerun-tasks.
  • My code follows the project's code style guidelines. I have run ./gradlew codeStyle and resolved any violations. See Code Style for details.
  • This PR does not include mass reformatting, style-only changes, or large-scale refactoring unless it was explicitly approved in the linked issue. Unsolicited reformatting will not be accepted.
  • If generative AI tooling was used in preparing this contribution, a quality model was used to ensure contributions are consistent with the project's quality standards.

Licensing and Attribution

Documentation

  • If this PR introduces user-facing changes, I have included or updated the relevant documentation.
  • If this PR adds a new feature, I have updated the What's New section of the Grails Guide.
  • If this PR introduces breaking changes or changes that require user action during an upgrade, I have updated the Upgrade Notes for the corresponding version in the Grails Guide.
  • The PR description clearly explains what was changed and why.

First-time contributors: Please read our Contributing Guide before submitting.
Pull requests that appear to be auto-generated, incomplete, or unrelated to an approved issue may be
closed to help maintainers focus on reviewed and planned work. We appreciate your understanding.

…tached criteria against the rest of its path

The check of the sort argument read a key that starts with the alias of a
detached criteria as a path from the queried class. A key whose alias is
not the name of a property, such as b.unknown for the alias b, was not
checked beyond the alias, and a key whose alias is the name of a property,
such as author.author.name for the alias author, was rejected although it
is a path through the alias.

A detached criteria whose query is given its alias now passes the alias to
the check. A key that starts with it is read as a path from the queried
class first, and only when it is not one is the alias stripped, once, and
the rest checked as a path from the queried class. A key without the alias,
and a query without one, are checked as before.
jdaugherty added a commit that referenced this pull request Dec 3, 2026
Carries #17255 (a JPA entity with several @id properties compiles), #17265
(the OAuth2 plugin accepts an intranet authorization url and redirects once
on an invalid one), #17072 (a sort by a collection joins it without changing
what the query fetches) and #17073 (a sort can start with the alias of the
queried class), from 7.0.x with 7fa74e0, and #17036 (runtime.groovy is
only read when application.groovy exists), from 7.2.x.

- GrailsHibernateQueryUtils keeps 7.x's populateArgumentsForListQuery and
  addSortArguments, which defer the fetches a collection sort would
  multiply, with 8.0.x's validation: an invalid direction is rejected before
  the sort is read, and every sort property is validated.
- HibernateSession imports HashMap and LinkedHashMap.
- JpaEntityTransformSpec keeps 8.0.x's features and adds 7.x's.
- UndefinedAliasSortSpec and CollectionFetchPaginationSpec register their
  domain classes with registerDomainClasses, as the other specs on 8.0.x do.
- The changes to the 7.0.18 notes are also in the 8.0.1 section of
  upgrading80x.adoc and in the 8.0.1 part of the upgrade skill, under
  "GORM for Hibernate 5".

Ten rows of UndefinedAliasSortSpec fail on 8.0.x until #17308, in that spec
and in RootAliasSortLegacySpec, which runs it with the setting disabled: 20
failures. They sort through a root alias that has the name of a property,
as club.club.name for new DetachedCriteria(Team, 'club') and
author.author.publisher.name for the alias author, with the sort argument
or a sort map. The validation of the sort argument that 8.0.x adds does not
know the alias of the criteria and rejects such a key with "Invalid sort
property". #17308 makes the validation follow the alias.
…n 8.0.x

8.0.x now has the sort through the alias of the queried class from 7.0.x,
so a key that resolves only through the alias of a detached criteria sorts
with Hibernate 5. The spec asserts the order in the sort argument, a sort
map and a sort of the criteria, and the notes say how the check of the sort
argument reads such a key in the note on the alias of the queried class
rather than in a note of their own.

@matrei matrei 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.

First round, at 47375f9. The base is 8.0.x at 482fbed. That is the merge of 7.2.x that brought #17073, along with the 20 failures that this pull request fixes.

Following #17274, each point says whether it is a change from 8.0.x that this pull request makes, a defect of the code it adds, or a case that behaves the same on 8.0.x. I hold my approval only for the points under "Still open".

What it fixes

The 20 failures reproduce on 8.0.x and pass here, and every row of the table in the description holds with GORM for Hibernate 5. I ran more keys with three teams: United First of the club United, Arsenal First of the club Arsenal, and Nomads, which has no club. A key that resolves only through an alias with the name of a property now sorts as sort() with the same key does:

new DetachedCriteria(Team, alias), Hibernate 5 8.0.x (482fbed) This head
alias club: list(sort: 'club.club.name'), also with order: 'desc', as a sort map, with ignoreCase: false, with a closure of more criteria, and after build { } or where { } Invalid sort property Arsenal First, United First, as with sort('club.club.name')
the same with max: 1 and offsets 0 and 1, and get(sort: 'club.club.name', max: 1) Invalid sort property one team on each page, totalCount 2
alias name: list(sort: 'name.name') Invalid sort property Arsenal First, Nomads, United First, as with sort('name.name')
alias address, of an embedded address: list(sort: 'address.address.city'); alias club: list(sort: 'club.club.id') Invalid sort property sorted by the city, and by the id of the club

A key that is a path from the team keeps that meaning, as club.name does for the alias club. t.name, t.club.name, t.id, t.address.city, t.foo.bar and the keys after this give the results of 8.0.x. With Hibernate 7, only count changes; see below.

Still open

  • count with a key whose rest after the alias is not a path: a change from 8.0.x, on a result that 8.0.x returns with Hibernate 5 and with Hibernate 7. The description says that no call that returned results returns other results. These counts did:

    new DetachedCriteria(Team, 't') 8.0.x, Hibernate 5 This head, Hibernate 5 8.0.x, Hibernate 7 This head, Hibernate 7
    count(sort: 't.unknown'), also with order: 'desc', as a sort map, and with 't.address.unknown' 3 Invalid sort property 3 Invalid sort property
    count(sort: 't.club.unknown') 2 Invalid sort property 3 Invalid sort property
    sort('t.unknown').count(), for comparison 3 3 3 3

    The check now strips an alias that is not the name of a property, and checks the rest. On 8.0.x, the check leaves a dotted key whose first segment is not a property to the query, and a count doesn't sort. The same count through sort() still returns 3. So the old result doesn't contradict what the call asks for, and under "Fixes That Change a Result" I don't see a case for this change on 8.0.x.

    The alias could be stripped only when it is also the name of a property of the queried class. That is the only case where 8.0.x's check rejects a key that the query reads through the alias, so the counts above would stay:

    if (entity != null && rootAlias != null && !rootAlias.isEmpty() && sort.startsWith(rootAlias + '.') && resolveProperty(entity, rootAlias) != null &&
            !isPropertyPath(entity, sort.split("\\."))) {

    I tried that line at this head:

    • The 20 rows pass.
    • Of the calls I ran with Hibernate 5 and 7, the only ones that change are calls that threw on 8.0.x. They give the results in the table under "What it fixes".
    • t.unknown and t.club.unknown behave as on 8.0.x: a Hibernate 5 list throws Hibernate's QueryException, and a count returns the count.
    • The two rows of the new feature that expect Invalid sort property for those keys fail.

    The third row of the description's table, and the sentences on b.unknown in the note and the skill, would then say what 8.0.x does.

  • The sentence that this pull request adds to the 8.0.1 note on an invalid rest: a defect of the text it adds. It says: "in the sort argument or a map of sort properties, the check that Grails 8 makes of every sort key rejects it with IllegalArgumentException: Invalid sort property". The paragraph before it covers both the alias of a detached criteria and this. After this, an invalid rest is not checked, here as on 8.0.x:

    • Team.where { … }.list(sort: 'this.unknown') throws Hibernate's QueryException. So does the same key in the sort argument of a criteria query, of a dynamic finder and of a detached criteria without an alias.
    • Team.list(sort: 'this.unknown') throws IllegalArgumentException: Unable to locate Attribute.

    Naming the alias of a detached criteria in that sentence, or the exception of each case, would keep it accurate, whichever way the first point goes. The same applies to the bullet in the skill.

Not blocking

  • The description's bullet on Hibernate 7: it says that Hibernate 7 rejects every sort that starts with the alias, before and after this change. That holds for list and get, but count now accepts such a key. new DetachedCriteria(Team, 'club').count(sort: 'club.club.name') was Invalid sort property and is now 2, as with Hibernate 5, and new DetachedCriteria(Team, 'name').count(sort: 'name.name') is now 3. These are calls that threw and now work, also with the line above, so the bullet could say that only the list still rejects these keys.
  • validateSortProperty(PersistentEntity, String, String): only DynamicFinder calls it, so it could be private. The only new public method on the patch branch would then be the overload of populateArgumentsForCriteria that DetachedCriteria needs.

What I ran

  • The Hibernate 5 and 7 tests: CI is still running at this head.

  • The new tests of this head and the 20 rows on 8.0.x (482fbed):

    • UndefinedAliasSortSpec and RootAliasSortLegacySpec fail there, with 20 failures.
    • Four rows of the new features of SortArgumentValidationSpec fail there: name.name, club.club.name, t.unknown and t.club.unknown.
    • The new feature of DynamicFinderCoverageSpec passes there too, since it pins a datastore that doesn't give a query the alias.

    All four specs pass at this head.

  • The rows above: 82 calls with Hibernate 5 and 7, on 8.0.x and at this head. They cover:

    • list, a sort map, get, count, paged lists, sort(), and build and where;
    • aliases with the name of an association, of a property and of an embedded component, and aliases with the name of none;
    • paths to an identifier, and keys after this.
  • The line above: at this head, with the same specs and 77 of the calls. The other five go through sort(), which the check doesn't read.

…e alias is the name of a property

The check of the sort argument leaves a dotted key whose first segment is
not a property to the query, and a count does not sort, so a key such as
t.unknown after the alias t gave the count on 8.0.x. The check now strips
the alias only when it is also the name of a property of the queried
class, the one case in which it rejected a key that the query reads
through the alias, so such a key is left to the query as before.

The note on the sort through the alias of the queried class keeps its
sentence on an invalid remaining property as on 8.0.x, and the check is
private to DynamicFinder.
@jdaugherty jdaugherty changed the title fix(datamapping): check a sort key that starts with the alias of a detached criteria against the rest of its path fix(datamapping): read a sort key through the alias of a detached criteria that has the name of a property Dec 3, 2026

@jdaugherty jdaugherty left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

At b25fc51.

count with a key whose rest after the alias is not a path. Taken: the check strips the alias only when it is also the name of a property of the queried class, with the condition from your review, and its javadoc says so. The two rows of the rejection feature of SortArgumentValidationSpec for t.unknown and t.club.unknown are gone. The feature has a row for a direction after an alias with the name of an association, club.club.name desc, and a new feature pins that count with t.unknown, also with order: 'desc', as a sort map and through sort(), and with t.club.unknown returns the count. The Hibernate 7 spec gets the counts with club.club.name, name.name, t.unknown and t.club.unknown, and the rejection of club.club.unknown.

With three teams, United First of the club United, Arsenal First of the club Arsenal, and Nomads, which has no club:

new DetachedCriteria(Team, alias) 8.0.x (482fbed), Hibernate 5 This head, Hibernate 5 8.0.x, Hibernate 7 This head, Hibernate 7
t: count(sort: 't.unknown'), also with order: 'desc' and as a sort map 3 3 3 3
t: count(sort: 't.club.unknown') 2 2 3 3
t: sort('t.unknown').count() 3 3 3 3
t: list(sort: 't.unknown') and list(sort: 't.club.unknown') Hibernate's QueryException Hibernate's QueryException Invalid sort property Invalid sort property
club: count(sort: 'club.club.name') Invalid sort property 2 Invalid sort property 2
name: count(sort: 'name.name') Invalid sort property 3 Invalid sort property 3
club: list(sort: 'club.club.name'), also as a sort map, and get(sort: 'club.club.name', max: 1) Invalid sort property Arsenal First, United First; get: Arsenal First Invalid sort property Invalid sort property
name: list(sort: 'name.name') Invalid sort property Arsenal First, Nomads, United First Invalid sort property Invalid sort property
club: list and count with club.club.unknown; name: count(sort: 'name.unknown') Invalid sort property Invalid sort property Invalid sort property Invalid sort property
no alias: count(sort: 'club.club.name') Invalid sort property Invalid sort property Invalid sort property Invalid sort property

The calls that change are the ones that threw on 8.0.x.

The sentence on an invalid rest in the 8.0.1 note. Taken: it is gone from the note and from the bullet of the skill, which read as on 8.0.x again there. What this pull request adds to both is that the check reads author.author.name as a path from the queried class first and through the alias second, so it no longer rejects it.

The bullet on Hibernate 7 in the description. Taken: it says that list and get still reject these keys, and that count returns 2 for club.club.name with the alias club and 3 for name.name with the alias name. The table and "Results that change" follow the narrowed check, and the title says what the check now does.

validateSortProperty(PersistentEntity, String, String). Taken: it is private. The only new public method is the overload of populateArgumentsForCriteria that DetachedCriteria calls.

What I ran at this head:

  • grails-data-hibernate5-core: 3834 tests, 0 failures, 176 skipped, with UndefinedAliasSortSpec and RootAliasSortLegacySpec, 93 each, and SortArgumentValidationSpec, 26.
  • grails-datamapping-core: 1833 tests, 0 failures.
  • Hibernate 7: SortArgumentValidationSpec 48, CriteriaMethodInvokerSpec 55, HqlListQueryBuilderSpec 52 and ListOrderBySpec 2, 0 failures.
  • The integration tests of the Hibernate 5 example application: 23, 0 failures, 3 skipped.
  • codeStyle of grails-datamapping-core, grails-data-hibernate5-core and grails-data-hibernate7-core.
  • The rows of the table: 19 calls with Hibernate 5 and with Hibernate 7, on 8.0.x at 482fbed and at this head.

@jdaugherty
jdaugherty requested a review from matrei December 3, 2026 14:03
@borinquenkid

Copy link
Copy Markdown
Member

I ran the base and the head on the same rows, to check the count finding independently of the table above.

Method. 8.0.x at 482fbed and this head, each with GORM for Hibernate 5 and with GORM for Hibernate 7. One probe over 4 aliases (none, t, club, name), 11 sort keys, and 4 forms (list(sort:), a sort map, sort(key).list(), count(sort:)), 176 rows per datastore. Teams United First of the club United and Arsenal First of the club Arsenal.

Hibernate 5, 9 of 176 rows differ

  • 6 rows sort now that failed on 8.0.x with Invalid sort property: club.club.name for the alias club, and name.name for the alias name, each as list, as a sort map and as count.
  • list and the sort map with t.unknown threw a Hibernate QueryException on 8.0.x and throw IllegalArgumentException: Invalid sort property here, as the upgrade note says.
  • count(sort: 't.unknown') returned 2 on 8.0.x and throws here.

Hibernate 7, 3 of 176 rows differ, all count

  • count(sort: 't.unknown') returned 2 and now throws, as on Hibernate 5.
  • count(sort: 'club.club.name') for the alias club, and count(sort: 'name.name') for the alias name, threw and now return 2.
  • list, the sort map and sort(key).list() are identical on 8.0.x and on this head for every key. Hibernate 7 does not read an alias in a sort on either: list(sort: 't.name') is rejected on both. So the Hibernate 7 change is count only, and nothing reaches a Hibernate 7 query that it cannot read.

This confirms @matrei's first open point: the count rows are the only place where a call that returned a result on 8.0.x now throws. Everything else that differs is the fix, or the exception type the upgrade note already states. I have no other finding.

@jdaugherty

Copy link
Copy Markdown
Contributor Author

Those rows are from 47375f9. b25fc51 takes matrei's narrowing: the alias is read only when it is also the name of a property, so t.unknown is left to the query as on 8.0.x: count(sort: 't.unknown') returns the count again with Hibernate 5 and 7, and a Hibernate 5 list throws Hibernate's QueryException again. The six rows that now sort and the two Hibernate 7 counts are as you measured. The table in my reply has each row on 8.0.x and at this head.

@matrei matrei 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.

Second round, at b25fc51. Since my review at 47375f9, b25fc51 makes these changes:

  • the check reads a sort key through the alias of a detached criteria only when the alias is also the name of a property of the queried class;
  • the check with the alias is now private;
  • the sentence on an invalid rest is gone from the note and the skill again.

Following #17274, each point says whether it is a change from 8.0.x that this pull request makes, a defect of the code it adds, or a case that behaves the same on 8.0.x. Nothing is left that I hold my approval for.

Fixed

  • count with a key whose rest after the alias is not a path (my review 6171092151): these counts return 8.0.x's results again, with Hibernate 5 and with Hibernate 7:

    • new DetachedCriteria(Team, 't').count(sort: 't.unknown') returns 3, also with order: 'desc' and as a sort map.
    • count(sort: 't.club.unknown') returns 2 with Hibernate 5 and 3 with Hibernate 7.

    A Hibernate 5 list with those keys throws Hibernate's QueryException again, as on 8.0.x. The condition is the one I tried, and the 77 calls of my probes that I ran with it give the same results here. Of all 82 calls, only those that threw Invalid sort property on 8.0.x change:

    • With Hibernate 5, club.club.name, club.club.id and address.address.city sort through an alias with the name of an association or of an embedded component. That holds in list, a sort map, get, a page and count, also after build { } and where { }. name.name sorts through an alias with the name of a property.
    • With Hibernate 7, only count changes, to 2 and 3.
  • The sentence on an invalid rest in the 8.0.1 note (my review 6171092151): the note and the skill read as on 8.0.x again there. What this pull request still adds to both is that the check reads author.author.name as a path from the queried class first and through the alias second, which holds.

  • The bullet on Hibernate 7 in the description: it now says that count accepts a key through an alias with the name of a property, while list and get still reject it. That matches my rows.

  • validateSortProperty(PersistentEntity, String, String): it is private. The only new public method is the overload of populateArgumentsForCriteria that DetachedCriteria calls.

Not blocking

  • The 8.0.x sentence on an invalid rest (behaves the same on 8.0.x, optional): "An invalid remaining property, such as b.unknown, now fails as an unqualified invalid property does" came with the 7.0.18 note, where both threw Hibernate's QueryException. On 8.0.x, the check rejects unknown in the sort argument with IllegalArgumentException: Invalid sort property. b.unknown, and this.unknown in a where query, still throw Hibernate's QueryException, here as on 8.0.x. The sentence could say that such a key fails in the query, but that is not for this pull request.

What I ran

  • The tests: CI is still running at this head, with no failure so far.

  • The tests of this head on 8.0.x (482fbed):

    • The 20 rows of UndefinedAliasSortSpec and RootAliasSortLegacySpec fail there.
    • Of the 26 cases of the Hibernate 5 SortArgumentValidationSpec, two fail there: the rows with name.name and club.club.name.
    • Of the 48 cases of the Hibernate 7 spec, one fails there: the new feature with the counts.
    • The new counts with t.unknown and t.club.unknown pass there as well, since they pin 8.0.x's result.

    At this head they all pass, with DynamicFinderCoverageSpec (52).

  • The rows above: 82 calls with Hibernate 5 and with Hibernate 7, on 8.0.x and at this head. They cover:

    • list, a sort map, get, count, pages and sort(), also after build { } and where { };
    • aliases with the name of an association, of a property and of an embedded component, and aliases with the name of none;
    • paths to an identifier, and keys after this.

@borinquenkid borinquenkid left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Approved at b25fc51.

I ran the base (8.0.x at 482fbed) and this head on the same rows: 4 aliases (none, t, club, name), 11 sort keys, 4 forms (list(sort:), a sort map, sort(key).list(), count(sort:)), 176 rows per datastore, with GORM for Hibernate 5 and with GORM for Hibernate 7.

Hibernate 5, 6 of 176 rows differ. All six are the fix: club.club.name for the alias club, and name.name for the alias name, each as list, as a sort map and as count. They threw Invalid sort property on 8.0.x and sort or count now.

Hibernate 7, 2 of 176 rows differ. Both are count: the same two keys, which threw and now return 2. list, the sort map and sort(key).list() are identical on both, since Hibernate 7 does not read an alias in a sort on either.

What the earlier head changed and this one does not. On 47375f9, count(sort: 't.unknown') and the list and sort-map forms with t.unknown differed from 8.0.x. Here every one of those rows is identical to 8.0.x, so the count finding is closed. The check with the alias is private, so no API is added on a patch line.

I have no finding. The tests and the upgrade note match what I ran.

@jdaugherty
jdaugherty merged commit 9cd5d17 into apache:8.0.x Dec 3, 2026
22 of 89 checks passed
@jdaugherty
jdaugherty deleted the fix/sort-validation-root-alias branch December 3, 2026 15:10
jdaugherty added a commit that referenced this pull request Dec 3, 2026
Carries, from 7.x: #17255, #17265, #17072, #17073 and #17036, with
7fa74e0, which makes grails-data-hibernate5-core compile after #17072
and #17073; and from 8.0.x: #17295 (nimbus-jose-jwt 10.11), #17076 (with
Hibernate 7, deleteAll and updateAll reject max and offset), #16725 and
#17296 (the mongodb-developer skill and the scoped agent guides), #17024
(Spock conditions in if blocks and loops are asserted), #16852 and #17029
(setup-gradle 6.4.1 and setup-java 6.3.0), and #17308 (the check of the
sort argument reads a key through the alias of a detached criteria that
has the name of a property).

- AGENTS.md keeps 8.1.x's description of grails-forge and takes 8.0.x's
  links to the agent guides of build-logic and grails-gradle.
jdaugherty added a commit that referenced this pull request Dec 3, 2026
Carries #17255, #17265, #17072, #17073 and #17036 from 7.x, with
7fa74e0, and #17295, #17076, #16725, #17296, #17024, #16852, #17029
and #17308 from 8.0.x.

- The sort of Hibernate 5 is the 7.0.x code with the rejection of a sort by
  an alias that the query does not define, as the merge-up section of
  #17074 asks, and keeps the declared root alias and this, as #17073 asks
  of the merge into 9.0.x. AbstractHibernateQuery strips the root alias
  once, as on 7.0.x, then checks the rest from the queried class or from a
  declared alias and throws "Invalid sort property" for anything else.
  Both addOrderPossiblyNested methods of GrailsHibernateQueryUtils handle
  the root alias and this first and then reject a name that is not a
  property. GrailsHibernateUtil keeps 9.0.x's rejection.
- UndefinedAliasSortSpec has 9.0.x's features for an undefined alias and
  7.x's for the root alias, so a sort through an alias with the name of a
  property sorts, with #17308's check, and an undefined alias is rejected.
- dependencies.gradle keeps 9.0.x's pins, with nimbus-jose-jwt 10.11.
- The upgrade skill keeps 9.0.x's side, the Grails 9 skill, which has no
  8.0.1 part.
- The 9.0.x job of benchmark.yml takes setup-java 6.3.0 and setup-gradle
  6.4.1, as the other jobs do.
- The count features of #17308's SortArgumentValidationSpecs follow
  9.0.x, where a count checks its sort as list does (#17074). With
  Hibernate 5, count(sort: 't.club.unknown') for the alias t is rejected,
  as club.unknown is; t.unknown still gives the count. With Hibernate 7,
  which does not sort through the alias of the queried class (#17167), a
  count rejects such a key, as list and get do.
jdaugherty added a commit to jdaugherty/grails-core that referenced this pull request Dec 3, 2026
Brings the merge of 7.2.x with the Hibernate 5 sort and join type changes of apache#17072 and apache#17073, apache#17308, which reads a sort key through the alias of a detached criteria and fixes the Hibernate 5 specs that the sort check rejected, and the test of nested association blocks of apache#16559. This branch changes nothing that they change, apart from the upgrade note and the skill, which merged without a conflict and keep the entries of both sides in their order. apache#17308 leaves a static list with a join type in its fetch argument as it was: it has no alias, and calls the overload without one.
jdaugherty added a commit that referenced this pull request Dec 3, 2026
Carries #17255, #17265, #17072, #17073 and #17036 from 7.x, with
7fa74e0, #17295, #17076, #16725, #17296, #17024, #16852, #17029 and
#17308 from 8.0.x, and 9.0.x's merge of them, which keeps the rejection
of a sort by an alias that the query does not define (#17074) beside the
sort through the root alias of 7.0.x.
jdaugherty added a commit that referenced this pull request Dec 3, 2026
Carries #17255, #17265, #17072, #17073 and #17036 from 7.x, with
7fa74e0, #17295, #17076, #16725, #17296, #17024, #16852, #17029 and
#17308 from 8.0.x, through 8.1.x, 9.0.x and 9.1.x.
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.

3 participants