Skip to content

fix(hibernate5): a setting keeps the entities without the association for an association block in or - #16931

Closed
borinquenkid wants to merge 17 commits into
7.2.xfrom
fix/h5-or-association-block-7.0.x
Closed

borinquenkid wants to merge 17 commits into
7.2.xfrom
fix/h5-or-association-block-7.0.x

Conversation

@borinquenkid

@borinquenkid borinquenkid commented Nov 11, 2026 •

Copy link
Copy Markdown
Member

An association block inside or { } is one branch of the disjunction. The criteria guide documents it that way: "all accounts that have either performed transactions in the last 10 days OR have been recently created in the last 10 days". The block is an inner join, so an account without transactions is dropped before the other branch can match it. A where query with || over an association does the same.

Results that change, and the setting

Association blocks in or are common, and no other query API of Hibernate 5 returns the new rows, so under "Fixes That Change a Result" in CONTRIBUTING.md the fix is behind a setting, grails.gorm.leftJoinAssociationInOr:

7.2.x and 8.0.x 8.1.0 9.0.0
Default false, today's results true (planned) removed

Setting it to false explicitly logs a startup warning naming Grails 9.

With true:

  • A block in or, in a criteria query, a detached criteria or a where query with ||, is a left join: the instances without the association are found by the other branches, also by count and the totalCount of a paged list.
  • The block still requires an associated entity that matches it. A block without criteria, a block outside an or and a block directly in a not require the association as before. In a criteria query, a block on an association of the entity's own class, left-joined by default, keeps its rows as before. A not is not treated as an or, because the criteria builder joins a block as it enters it, before it knows how many criteria the not holds.
  • The left join of a collection for such a block is restricted, as the base already does for a paged collection sort, so Hibernate does not fill the collection with only the elements that the block matches.

With or without the setting:

  • A block that names an inner join, or that names no join type, requires the association after a block on the same association that named a left join. A block that names an inner join also requires it after a block on an association of the entity's own class.
  • The in-memory datastore requires the association for a block without criteria, as Hibernate does. Such a block matched no row before.

To keep the previous results of an or, leave the setting unset.

Tests

  • CriteriaOrAssociationSettingSpec (Hibernate 5) runs a to-one association, a collection and a collection in a join table through a criteria query, a detached criteria, a where query, count and a paged list, with the setting unset, false and true, and reads the collections of the instances returned. The unset and false rows for those queries also pass on plain 7.2.x.
  • The shared TCK specs CriteriaOrAssociationSpec and CriteriaOrAssociationBlockSpec (MongoDB skipped, it has no association blocks) run the block rows; on Hibernate 5 with the setting.
  • HibernateDatastoreSpec pins the warning.
  • grails-data-hibernate5-core, grails-datamapping-core-test, grails-datastore-core, grails-core, grails-data-mongodb-core and codeStyle pass.

CriteriaOrAssociationBlockSpec also runs on Neo4j and passes there with #16836, so merge #16836 first. The open parts of #16853 touch the same builder, so this needs another merge after them.

Fixes #16924
Evidence and the doc passage: #16924 (comment)

https://claude.ai/code/session_01Dmki4RzWwreEC2GkkyFnvL

…e entities without the association

The criteria guide documents an association block inside or as one branch:
accounts that have either performed transactions OR were recently created.
The block was an inner join, so an account without transactions was dropped
before the other branch could match it. A block that has no join type of its
own, inside an or, is now a left join.

Fixes #16924

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

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.

Not approving. An association block that accepts a null now matches an entity that has no association. A later explicit inner join also reuses that left join.

…ociated entity

A null test in the block matched the entities without the association, because the
left join gives null for the missing one. The block now also requires the id of the
joined alias. The shared block cases skip Neo4j until #16836 is merged.

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

@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 null test in an association block no longer matches an entity that has no association. Thread PRRT_kwDOAAfRJ862Qfia resolved. Not approving. An empty association block no longer requires the association, and a later inner join reuses the left join.

…uires an associated entity, and an empty block does too

A block outside an or that reuses the left join of a block in one no longer returns the entities without the
association, and an empty block in an or keeps requiring an associated entity of the whole entity, as its inner join did.

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

An empty association block requires the association again, and a later inner join no longer reuses the left join as if the child were optional. Threads PRRT_kwDOAAfRJ862VrVg and PRRT_kwDOAAfRJ862VrVl resolved. Not approving. A later block that asks for a left join is treated as if it required the child.

…r not an or joined the association with a left join

or { child {...}; eq(...) }; child(LEFT_JOIN) { isNull('name') } keeps the entity without a child, as the left join the
second block asked for does.

@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 later block that asks for a left join keeps that left join. Not approving. A later block that asks for an inner join still reuses the left join.

// a block that is a branch of an "or" asks for an associated entity, and so does a block that
// reuses the left join of one, as a block outside an "or" always did
// (a join type the caller named is kept as the caller named it)
final boolean requiresAssociated = branchOfOr || (!hasMoreThanOneArg && leftBlockAliases.contains(blockAlias));

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.

or { child { eq('name', 'kid') }; eq('name', 'orphan') }; child(CriteriaSpecification.INNER_JOIN) { isNull('name') }, where orphan has no child. The list returns orphan. The later block asked for an inner join. Require the child.

@borinquenkid
borinquenkid requested a review from matrei November 12, 2026 14:12
…and is no branch of an or

CriteriaOrAssociationBlockSpec expects an association block without criteria
to leave out the entities that have no associated entity, and to add no
branch to the or it stands in, as on the datastores that join. The in-memory
store matched nothing for the block and let the other branch of the or find
the orphan.

The block is now skipped as a branch and the whole result is restricted to
the entities that have an associated entity.

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

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

Requested changes. An explicit inner join after an or reuses the left join, so an entity without the association is kept.

// a block that is a branch of an "or" asks for an associated entity, and so does a block that
// reuses the left join of one, as a block outside an "or" always did
// (a join type the caller named is kept as the caller named it)
final boolean requiresAssociated = branchOfOr || (!hasMoreThanOneArg && leftBlockAliases.contains(blockAlias));

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.

with has a child named kid. orphan has no child. or { child { eq('name', 'kid') }; eq('name', 'orphan') } then child(INNER_JOIN) {} should return only with. It returns with and orphan. The second block reuses the left join from the or, and the extra argument turns off the existence check. Keep the inner join when the caller asks for one.

…d a block in an or of a detached criteria keeps its left join

child(INNER_JOIN) { } after an or reused the left join the or had made for the same association and, as it named a join
type, skipped the existence check, so an entity without the association stayed in the result; a block that names an
inner join asks for an associated entity now. The query path of a detached criteria had no rule for a block that is a
branch of an or at all, so an entity without the association dropped out of the or, an empty block did not ask for an
associated entity and a block after the or did not either; it makes a left join for such a block, checks for an
associated entity as criteria does, and does not count a negation as an or. CriteriaOrAssociationBlockSpec runs
each row through criteria and through a detached criteria, and has the explicit join type rows.

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

Copy link
Copy Markdown
Member Author

@jamesfredley Fixed in the new commit.

Your case. or { child { eq('name', 'kid') }; eq('name', 'orphan') } followed by child(INNER_JOIN) {} returned with and orphan: the second block reused the left join the or had made for child, and because it named a join type it skipped the existence check. A block that names an inner join asks for an associated entity now when it reuses such a join, so only with comes back. CriteriaOrAssociationBlockSpec has it with an empty block, with eq('name', 'kid') in it, and an explicit inner join inside the or, which stays inner. An explicit left join after the or is kept as the caller named it (child(LEFT_JOIN) { isNull('name') } finds orphan).

The same rule through the other entry point. I ran every row of that spec through a detached criteria as well, and four of the eight earlier rows failed there: the query path used by detached criteria had no rule for a block that is a branch of an or, so an entity without the association dropped out of the or, an empty block did not ask for an associated entity, and neither did a block after the or. It makes a left join for such a block now, checks for an associated entity the way the criteria builder does, and does not count a not { } as an or. A where query already kept the entity. A detached criteria takes an alias as the first argument of a block, not a join type, so the rows that give a join type run through criteria only, and on Hibernate only (the in-memory store has no such argument).

The H5 module (705 tests), the in-memory store and codeStyle pass; five rows fail without the change.

borinquenkid added a commit that referenced this pull request Nov 17, 2026
…nd a path a block repeats keeps one join

getOrCreateAlias reused the join of any earlier block of the same name whenever the block came with an alias, which a
block of a detached criteria always does, so dam { sire { ... } } filtered on the join of the root sire block and
returned nothing, and a second dam.sire block asked Hibernate for the same association path twice and failed with
a duplicate association path. The join made for the very path of the block is reused now, and a join made for the
same name under another path is not. The pedigree shapes of CriteriaNestedShapesSpec are checked through a detached
criteria as well, with the repeated nested blocks; the blocks that are branches of an or stay on criteria until #16931.

Claude-Session: https://claude.ai/code/session_01Dmki4RzWwreEC2GkkyFnvL
borinquenkid added a commit that referenced this pull request Nov 17, 2026
…d criteria

The detached criteria path keeps a left join for a block that is a branch of an or since #16931 (merged into this
branch), so the three shapes that were checked through criteria only are checked through both.

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

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

Requested changes. An explicit inner join after one or is kept. The same join inside a second or still lets an entity without the association through.

}
else if (requiresAssociated) {
// a missing associated entity is a null that a null test in the block would match
logicalExpression.args.add(0, Restrictions.isNotNull(blockAlias + ".id"));

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.

with has a child named kid. orphan has no child. An or that asks for the child, then a second or with child(0), should return only with. It returns with and orphan. The existence check sits inside the second or, so the name branch bypasses it. Keep that check on the whole query.

…ation on the whole query

A block that names an inner join and reuses the left join of a block in an earlier or kept its existence check
inside its own expression, so a branch of the second or that does not mention the association bypassed it.
The caller asked for an inner join, so the check is on the whole query, as for a block without criteria.

Claude-Session: https://claude.ai/code/session_01Dmki4RzWwreEC2GkkyFnvL
…an or

Ten shapes of a block that follows an or asking for the child: at the top level, as a branch of a second or,
and in a not, each with a plain, an inner join and a left join block, and with and without criteria.

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

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

Requested changes. An explicit inner join inside an or still lets an entity without the association through when an earlier block joined it.

final boolean explicitInnerJoin = hasMoreThanOneArg &&
joinType == org.hibernate.sql.JoinType.INNER_JOIN.getJoinTypeValue();
final boolean requiresAssociated = branchOfOr ||
(leftBlockAliases.contains(blockAlias) && (!hasMoreThanOneArg || explicitInnerJoin));

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.

An earlier manager block joins manager. Then two or blocks follow, and the second asks for manager as an inner join. orphan, who has no manager, still comes back. The earlier join is not recorded, so the inner join reuses it and adds no check. Keep orphan out.

@borinquenkid

Copy link
Copy Markdown
Member Author

@jamesfredley I ran your manager shape. The orphan comes back when the association points at its own class (manager is an Employee), and plain 7.0.x returns the same results, so the PR did not change it. The block is joined with a left join by the "same table" rule and nothing records it. The same shapes on an association to another class are correct on this head: an empty block that names an inner join asks for the association on the whole query.

I filed it as #17113 and kept it out of this PR.

@borinquenkid

Copy link
Copy Markdown
Member Author

James, found it. The entity has an association of its own class, like your manager. A plain block on it is left-joined by default, and nothing recorded that, so the later block that names an inner join reused the left join and added no check. A block that names an inner join asks for the association now, also after that default left join. I probed every three-block combination on a self-referencing entity, 30 of which let an entity without a manager through before, and none do now; the probe stays as CriteriaSelfReferenceInnerJoinSpec. The PR had no upgrade note, so the guide and the skill describe the or branch and this case. Merged 7.0.x too.

@borinquenkid
borinquenkid marked this pull request as draft November 26, 2026 00:58
Port the left join of an association block in an or onto the deferred joins:
createJoin makes the join of an or branch a left join unless the query asks for another type.
Three base specs pinned the inner join of an or branch; they now expect the rows an or branch keeps.

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

Copy link
Copy Markdown
Member Author

Refreshed against 7.0.x after the merge-up (merge commit ce1ec87). The base now makes joins when the query runs (deferred joins), so the left join of an association block in an or is now decided in createJoin: an or branch is a left join unless the query asks for another join type, and the criteria builder and the where/detached path keep the null-test rules they had.

Three specs that came in with the merge-up pinned the inner join of an or branch, which is the result this PR changes, so I changed their expectations rather than the fix:

  • AssociationJoinTypeSpec, "a join type requested for an association is not used for a nested association of the same name": team.club.name == 'Arsenal' || name == 'Unattached Player' now also finds the player without a team, because the team.club block is a branch of an or. An explicitly requested join type still wins, and the INNER case in the neighbouring spec is unchanged.
  • NestedRequestedLeftJoinSpec, "a nested LEFT request does not replace a genuine intermediate association restriction": or { eq('name', 'Empty'); children { ... } } keeps Empty, which matches on its own name. I added the same check without the or, which still returns only Populated.
  • Their LeftJoinSort and LeftJoinEnabled variants follow.

Verified on ce1ec87: H5 core 1406 tests, 0 failures; datamapping-core-test 585, 0 failures; codeStyle clean. With the fix reverted, 12 specs fail.

This changes a result on 7.0.x, so it needs two approvals.

https://claude.ai/code/session_01Dmki4RzWwreEC2GkkyFnvL

@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 ce1ec87. The branch merges cleanly with 7.0.x at ffd848b. CI hasn't run: the no ci label skipped all 30 checks.

I ran the 46 queries of my review of #16930 at this head and on 7.0.x:

  • with Hibernate 5;
  • with the in-memory store, plus seven blocks without criteria.

The fixture:

  • the teams Arsenal and Playerless play for the club Arsenal, Chelsea and Squad for Chelsea, and MU for Manchester United;
  • the teams Unattached and Empty have no club;
  • Squad has the players Squad A, Squad B and Squad C, Playerless and Empty have none, and the other teams have one each;
  • the club Teamless has no team, and the player Free Agent has no team.

I agree with the fix. The criteria guide describes the or as either branch, and the in-memory store already returns the new rows for every query in the first table. Apart from the to-many rows below, #16930 returns the same rows with Hibernate 7.

The fix changes a result, so #17061 applies

7.0.x This head
Team.createCriteria().list { or { club { eq('name', 'Arsenal') }; eq('name', 'Unattached') } }, also as a detached criteria, with count(), and with max: 10 and its totalCount Arsenal, Playerless Arsenal, Playerless, Unattached
Team.where { club.name == 'Arsenal' || name == 'Unattached' }.list(), also with club { name == 'Arsenal' } Arsenal, Playerless Arsenal, Playerless, Unattached
or { isNull('club'); club { eq('name', 'Arsenal') } } Arsenal, Playerless also Unattached and Empty
not { or { club { eq('name', 'Arsenal') }; eq('name', 'MU') } } Chelsea, Squad also Unattached and Empty
Player.createCriteria().list { or { team { eq('name', 'Squad') }; eq('name', 'Free Agent') } } the three players of Squad also Free Agent
Team.createCriteria().get { or { club { eq('name', 'Teamless') }; eq('name', 'Empty') } } null Empty

borinquenkid's comment of 11-28 says that this changes a result on 7.0.x and needs two approvals. Under "Fixes That Change a Result" in CONTRIBUTING.md, it's also a wrong result that many applications get:

  • an association block in an or, and a where query with || over an association, are common queries;
  • no other query API of Hibernate 5 returns the new rows yet: the where query returns the old ones too.

So it needs a setting:

  • Default: off on 7.0.x, 7.1.x, 7.2.x and 8.0.x, on from 8.1.0, and removed in 9.0.0.
  • Key: the same as in #16930, which makes the same fix for Hibernate 7. This branch is the fix for the oldest branch with the bug, so it goes first.
  • Warning: a warning at startup when an application sets the setting to keep the old rows.

It also needs:

  • the description to say which results change, how an application gets the old ones, and why there's a setting;
  • a row in compatibilitySettings.adoc;
  • an issue for each of the two later steps.

The note and the skill entry are there. They speak only of a block in a criteria query, though. The where query changes too, as the expectation that the merge changed in AssociationJoinTypeSpec shows, so the note should name it.

A collection holds only the elements that the block matches

The left join of a block on a collection makes Hibernate fetch the collection from the rows of the join, and the block's criterion has left out the other elements:

7.0.x This head
Team.createCriteria().list { or { players { eq('name', 'Squad A') }; eq('name', 'Empty') } }, also as a where query players.name == 'Squad A' || name == 'Empty' Squad, its players not loaded Squad, holding only Squad A, and Empty
or { club { eq('name', 'Arsenal') }; players { eq('name', 'Squad A') } } Arsenal, Squad also Playerless, and Squad holds only Squad A
  • Why it matters: the session keeps that Squad until it's cleared, so the rest of the request sees a team with one player.
  • Not new for an explicit left join: a block that names one, players(1) { eq('name', 'Squad A') }, does the same on 7.0.x.
  • New for a block without a join type: this branch makes it the default for a block in an or.
  • Hibernate 7 at #16930: it doesn't load the collection there.

For a collection, a restriction with a subquery would keep the instances without elements and fill no collection. On 7.0.x, a join type requested for a path that ends in a collection, or passes through one, already restricts the query that way. A test for this case should check the elements of the collection that the query returns.

A not with more than one criterion

The code doesn't count the criteria of a not as branches of an or ("they are not branches of an or: a block in one keeps its join"). But not { a; b } means not (a or b), and the two forms differ at this head:

7.0.x This head In-memory store, both
not { or { club { eq('name', 'Arsenal') }; eq('name', 'MU') } } Chelsea, Squad Chelsea, Squad, Unattached, Empty Chelsea, Squad, Unattached, Empty
not { club { eq('name', 'Arsenal') }; eq('name', 'MU') } Chelsea, Squad the same as on 7.0.x Chelsea, Squad, Unattached, Empty

I'd treat a not of more than one criterion as an or, here and in #16930. If not, the note should say that only or keeps the entities without the association.

The in-memory store

The change to SimpleMapQuery changes what the in-memory store returns for a block without criteria. So the unit tests of an application that use the store can get other rows:

7.0.x This head
Team.createCriteria().list { club { } }, also in and or or, and as a detached criteria no team the 5 teams with a club
Team.createCriteria().list { players { } } no team the 5 teams with players
or { club { }; eq('name', 'Unattached') } Unattached no team
club { }; or { club { eq('name', 'Chelsea') }; eq('name', 'Unattached') }, also with club { } after the or no team Chelsea, Squad

These are now the rows of Hibernate 5, which is the right direction for a store that unit tests use in place of Hibernate. The description and the note should say so.

Smaller points

  • The open #16853 parts: this branch conflicts with #17070 to #17073 in AbstractHibernateCriteriaBuilder.java. They're ahead in the queue, so this branch will need another merge with 7.0.x after them, and I'll run the rows again then.
  • The earlier reviews' points that I ran:
    • or { club { isNull('name') }; eq('name', 'nobody') } returns nothing;
    • or { club(0) { eq('name', 'Arsenal') }; eq('name', 'Unattached') } keeps the inner join;
    • club { } before or after the or still requires the club.
  • James's case on an association to its own class: #17113 has it, as the comment of 11-21 says.

What I ran

  • Hibernate 5: at this head and on 7.0.x (ffd848b).
  • The in-memory store: in grails-datamapping-core-test, at the same two heads.
  • Hibernate 7: for the comparison with #16930, at d6fa6db.

As a fix that changes a result, this needs a second approval under #17061.

….leftJoinAssociationInOr, and fill no partial collection

A block in an or that joins its association with a left join changes the result of queries that many applications
run, so it is behind a setting that is off by default. The left join of a collection for such a block is restricted,
so Hibernate does not fill the collection with only the elements that the block matches. Add the setting to the
compatibility page, the upgrade note for 7.2.6 and the upgrade skill.

Claude-Session: https://claude.ai/code/session_01Dmki4RzWwreEC2GkkyFnvL
…ows of a block on the entity's own class

A criteria block on an association of the entity's own class is left-joined without the setting and asks for no
associated entity. With the setting it was asked for one as a branch of an or, so the query lost rows.

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

Copy link
Copy Markdown
Member Author

@matrei Thanks, done in 4fb4be1 and cca0a1f.

https://github.com/apache/grails-core/blob/cca0a1f4f2/grails-data-hibernate5/core/src/main/groovy/org/grails/orm/hibernate/query/AbstractHibernateQuery.java#L642-L644
https://github.com/apache/grails-core/blob/cca0a1f4f2/grails-data-hibernate5/core/src/main/groovy/org/grails/orm/hibernate/query/AbstractHibernateCriteriaBuilder.java#L2008-L2011
https://github.com/apache/grails-core/blob/cca0a1f4f2/grails-data-hibernate5/core/src/test/groovy/grails/gorm/tests/CriteriaOrAssociationSettingSpec.groovy#L74

@borinquenkid borinquenkid changed the title fix(hibernate5): an association block that is a branch of or keeps the entities without the association fix(hibernate5): a setting keeps the entities without the association for an association block in or Nov 28, 2026
@borinquenkid
borinquenkid requested a review from matrei November 28, 2026 20:36
@testlens-app

testlens-app Bot commented Nov 28, 2026

Copy link
Copy Markdown

✅ All tests passed ✅

🏷️ Commit: cca0a1f
▶️ Tests: 68906 executed
⚪️ Checks: 62/62 completed


Learn more about TestLens at testlens.app/docs.

@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 cca0a1f:

The branch merges cleanly with 7.2.x at a19d39f. CI passed with run ci.

I ran the 66 queries of my second review of #16930, with the same fixture. I also ran seven on an association of the entity's own class: Employee has a manager, and the employees are boss, worker (managed by boss) and orphan. I ran them:

  • with Hibernate 5 at this head, with grails.gorm.leftJoinAssociationInOr unset and true, on 7.2.x (a19d39f) and on 7.0.x (6e69247);
  • with Hibernate 7 at #16930 (91a18da), with the setting unset and true.

I also ran the 53 queries of my first review on the in-memory store, at this head and on 7.2.x.

Fixed

  • The setting:

    • it has the same key as #16930, the startup warning, the compatibility settings row, the upgrade note and the skill entry;
    • #17210 and #17211 are the later steps;
    • with the setting unset, this head returns the rows of 7.2.x for 72 of the 73 queries.

    The one that differs is a change that the note lists under "with or without the setting": or { club(1) { eq('name', 'Arsenal') }; eq('name', 'Unattached') }; club { isNull('name') } returns no team, where 7.2.x returns Unattached.

  • The same rows as #16930: with true, this head returns what #16930 returns with true, for each query that both modules can run. The exceptions are:

    • the differences between the two modules that they have without the setting too;
    • the join type of a detached block, which my review of #16930 asks to leave to an issue for both modules;
    • the block on the entity's own class below.
  • A collection holds all of its elements: or { players { eq('name', 'Squad A') }; eq('name', 'Empty') }, its where form and or { club { eq('name', 'Arsenal') }; players { eq('name', 'Squad A') } } don't load the players of Squad any more. At ce1ec87, Squad held only Squad A. CriteriaOrAssociationSettingSpec reads the elements.

  • The where query and the in-memory store: both are in the note and the description. The in-memory store returns the rows of my first review for the blocks without criteria.

  • A not with more than one criterion: the note says that only an or keeps the entities without the association.

The base branch

borinquenkid's comment of 11-28 moves this to 7.2.x, because "After the 2026-11-25 releases the 7.x line takes fixes on 7.2.x only." There were no such releases:

  • the votes on 7.0.18, 7.1.8 and 7.2.5 were cancelled, and the latest tags are v7.0.17, v7.1.7 and v7.2.4;
  • 7.0.x still takes fixes: #17194 and #17207 were merged there on 11-28, and the open parts of #16853 target it;
  • I know of no decision on dev@ to stop fixes on 7.0.x and 7.1.x.

Under "Choosing the Branch" in CONTRIBUTING.md, the fix goes to the oldest release branch that has the bug, with the setting off on 7.0.x, 7.1.x, 7.2.x and 8.0.x. 7.0.x returns the same rows as 7.2.x for all 73 queries, so it has the bug. So I'd move this back to 7.0.x:

  • The branch: it has 7.2.x merged in now, so it needs to be built again from 7.0.x, for example from ce1ec87 with 7.0.x merged in and the two new commits on top.
  • The notes: the note goes under 7.0.18 in upgrading60x.adoc, and the skill entry into its 7.0.18 part.
  • The version: @since, the compatibility settings row and its link say 7.0.18, and the table in the description starts at 7.0.x. #16930 says @since 7.2.6 in ConnectionSourceSettings too.

Even on 7.2.x, the next release is 7.2.5, not 7.2.6. The note opens a 7.2.6 section after the 7.2.5 section, and 7.2.5 hasn't been released.

A not inside an or

This is the same point as in my review of #16930. With true, a block in a not that is inside an or keeps the entities without the association. The same not outside an or leaves them out. So the or returns a team that neither of its branches returns:

Unset true
Team.createCriteria().list { not { club { eq('name', 'Arsenal') } } } Chelsea, MU, Squad Chelsea, MU, Squad
Team.createCriteria().list { or { not { club { eq('name', 'Arsenal') } }; eq('name', 'Empty') } } Chelsea, MU, Squad Chelsea, Empty, MU, Squad, Unattached

Unattached has no club and isn't named Empty. I'd put the existence check of such a block outside the not: club.id is not null and not (club.name = 'Arsenal'). The or then returns Chelsea, Empty, MU and Squad. If not, the note should say that a block in a not keeps the entities without the association inside an or, but not outside one.

Smaller points

  • A block on the entity's own class: with true, the two pull requests differ for a null test in such a block:

    7.2.x and this head, unset This head, true #16930, true
    Employee.createCriteria().list { manager { isNull('name') } } boss, orphan boss, orphan boss, orphan
    Employee.createCriteria().list { or { manager { isNull('name') }; eq('name', 'orphan') } } boss, orphan boss, orphan orphan
    the same as a detached criteria no employee orphan orphan

    This branch keeps the left join that Hibernate 5 gives such a block in a criteria query, which asks for no manager (#17113). Leaving it to #17113 is fine, but #17113 should say that the two modules differ here with the setting. #17113 isn't only Hibernate 5's either: on 8.0.x, Hibernate 7 also returns boss and orphan for manager { isNull('name') }.

  • Merging up: this branch has the shared specs and the in-memory store change, which #17188 adds on 8.0.x. The in-memory change is the same in both, but CriteriaOrAssociationBlockSpec differs:

    • this branch's version turns the setting on through the configuration map of the Hibernate 5 TCK manager, which the Hibernate 7 manager doesn't have;
    • #17188's version turns it on through grailsConfig and skips Hibernate 5.

    The merge up to 8.0.x needs a spec that sets the setting for both managers and runs with both modules.

  • The open #16853 parts: this branch conflicts with #17070 to #17073 in AbstractHibernateCriteriaBuilder.java, and with #17072 and #17073 in AbstractHibernateQuery.java too. So it needs another merge after them, as the description says, and I'll run the rows again then.

What I ran

  • Hibernate 5: at this head, with the setting unset and true, on 7.2.x (a19d39f) and on 7.0.x (6e69247).
  • Hibernate 7: at #16930 (91a18da), with the setting unset and true, and on 8.0.x (42951ae).
  • The in-memory store: in grails-datamapping-core-test, at this head and on 7.2.x.

As a fix that changes a result, this needs a second approval under #17061.

@borinquenkid

Copy link
Copy Markdown
Member Author

@matrei You are right about the releases: my comment of 11-28 was wrong. The votes on 7.0.18, 7.1.8 and 7.2.5 were cancelled, and 7.0.x still takes fixes.

I moved this back to 7.0.x as #17234. It is a new pull request, because moving this branch would have meant a force push.

  • not inside or: your first option. The existence check of such a block is outside the not, for criteria queries, detached criteria and where queries.
  • Narrower: with the setting unset or false, queries return what they return on 7.0.x. What changed without the setting is no longer in it: the extra requirement after a block that named a left join, the one after the default left join of a block on the entity's own class, and the in-memory store change.
  • Also fixed: a not block after an or returned the instances without the association, and, with the setting on, a null test in an or returned nothing when the query requested a left join.
  • Own class: the requirement after the default left join is the case James raised. H5 criteria: an association block on a self-referencing association is joined with a left join and asks for nothing #17113 covers it.

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