Skip to content

fix(datamapping): a createAlias path that starts with an alias declared earlier continues the path of that alias - #17105

Open
borinquenkid wants to merge 1 commit into
7.0.xfrom
fix/detached-criteria-alias-chain-7.0.x
Open

borinquenkid wants to merge 1 commit into
7.0.xfrom
fix/detached-criteria-alias-chain-7.0.x

Conversation

@borinquenkid

Copy link
Copy Markdown
Member

A path given to createAlias on a DetachedCriteria or a where query that starts with an alias declared earlier now continues the path of that alias: after createAlias('children', 'c'), the path c.related is children.related. Before, such a call failed with a QueryException or with invalid SQL, so no working code changes (Fixes #14647).

This is the 7.0.x part of #16890, split out as matrei asked on that pull request: a bug fix with no new API, in AbstractDetachedCriteria only. The rest of #16890 (the MultipleAliasesMappingContext opt-in and the Hibernate 5 builder changes) is not here.

  • DetachedCriteriaAliasChainSpec: four features; the two that join from an earlier alias fail on 7.0.x without the change.
  • grails-datamapping-core (252 tests) and grails-data-hibernate5-core (691 tests) pass, and codeStyle is clean.
  • The upgrade note is in the 7.0.18 section of upgrading60x.adoc; a call that failed before now works, and a first segment that is both an alias and a property names the alias.

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.

@testlens-app

testlens-app Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

🚨 All tests passed but jobs failed 🚨

Failed Jobs without Test Failures

❌ Code Style / Forge Projects

🏷️ Commit: 63e8e8b
▶️ Tests: 60051 executed
⚪️ Checks: 58/58 completed

Rerun Controls

Click the checkbox to trigger a rerun:

  • Rerun jobs

Learn more about TestLens at testlens.app/docs.

@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 alias declared inside a block is not seen by the next alias in that block.

return associationPath
}
String head = associationPath.substring(0, dot)
for (Query.Criterion criterion in criteria) {

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 alias named c is declared for children, then c.related is declared, both inside the same and. The second call starts from the root and throws, because c was added to the and and this only looks at the top list. Continue from c.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@jamesfredley: confirmed. An alias declared inside and, or or not is not seen by a later alias that continues it, and the cause is wider than the lookup: on Hibernate 5 an association criterion with a dotted path inside a block is translated against the root, so fixing the lookup only moves the failure from createAlias to the query (all six block shapes fail that way). Fixing it properly changes how H5 and AbstractDetachedCriteria track aliases, which is too large for a 7.0.x patch release.

Workaround: declare the aliases at the top level and use them inside the block. That works and is covered by the specs in this PR, which is the chain #14647 reported.

The lookup fix itself works on H7 for all eight block shapes (top level, and, or, not, nested, split, outer first, full paths), so it goes to 8.1.x, with the split of the class in #17109.

https://claude.ai/code/session_01Dmki4RzWwreEC2GkkyFnvL

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

3 participants