Repository navigation
fix(datamapping): a createAlias path that starts with an alias declared earlier continues the path of that alias - #17105
borinquenkid wants to merge 6 commits into
Conversation
…ed earlier continues the path of that alias Claude-Session: https://claude.ai/code/session_01Dmki4RzWwreEC2GkkyFnvL
jamesfredley
left a comment
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
@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.
…a-alias-chain-7.0.x
…ock is refused with the way to declare it Claude-Session: https://claude.ai/code/session_01Dmki4RzWwreEC2GkkyFnvL
|
James, the alias declared inside a block is a refusal now, as 7.0.x has no room for the full lookup fix. A path that continues an alias declared inside |
jamesfredley
left a comment
There was a problem hiding this comment.
Requested changes. An alias named like a property of the root is still not continued inside a block.
| // a block that is still open is not in the criteria yet | ||
| List<Query.Criterion> inBlocks = new ArrayList<Query.Criterion>(criteria) | ||
| inBlocks.addAll(junctions) | ||
| if (declaredInBlock(inBlocks, head) && persistentEntity.getPropertyByName(head) == null) { |
There was a problem hiding this comment.
An alias named name is declared for related, then name.tag is declared, both inside the same and. The root also has a property named name. The second call starts from that property and throws. Continue from the alias.
…de a block also where the class has a property of that name The refusal was skipped when the class had a property named like the alias, so the path started from that property and failed with 'is not an association'. The alias names the first segment, as it does at the top level, so the refusal applies. Claude-Session: https://claude.ai/code/session_01Dmki4RzWwreEC2GkkyFnvL
|
@jamesfredley Fixed. The refusal was skipped when the class had a property named like the alias, so |
jamesfredley
left a comment
There was a problem hiding this comment.
Requested changes. An alias declared inside a block is still refused when it does not collide with a root property.
| // the alias names the first segment, also where the class has a property of the same name, and it cannot be | ||
| // continued from here: the path would start from the root and fail further on, or find the wrong association, | ||
| // so say what to do | ||
| throw new IllegalArgumentException("The alias [$head] is declared inside a block (and, or, not), and the path [$associationPath] cannot continue from it there. Declare the alias at the top level of the query and use it inside the block.") |
There was a problem hiding this comment.
An alias named c is declared for children, then c.related is declared, both inside the same and. The root has no property named c. The second call is refused and told to declare c at the top. Continue from c.
…r it was declared, and declared by its path inside a block
An alias declared inside and, or or not was refused when a path continued it, although the alias belongs to the whole query. It is found in
the closed blocks and in the block that is still open now. Hibernate 5 then declared such an alias inside a junction by the name of its
association alone, so createAlias('c.related', 'r') looked for related on the root; it is declared by the path from the root, as it is outside
a block. DetachedCriteriaAliasChainSpec has the table of declaration sites for a detached criteria and for the criteria builder.
Claude-Session: https://claude.ai/code/session_01Dmki4RzWwreEC2GkkyFnvL
|
@jamesfredley Fixed, and the refusal is gone: an alias belongs to the whole query, so a path that continues it is found wherever the alias was declared. Behind the refusal there was a second bug that your example only reaches once the first is out of the way: Hibernate 5 declared an alias inside The table in
Not covered, with the reason: a second alias for the same collection is not a separate join on Hibernate 5 (it keeps the latest alias of a path, as it always has; Hibernate 7 on 8.0.x joins each one), and |
🚨 All tests passed but jobs failed 🚨Failed Jobs without Test Failures❌ CI / Build Grails-Core (macos-latest, 21, true) 🏷️ Commit: 36d6b4f Rerun ControlsClick the checkbox to trigger a rerun:
Learn more about TestLens at testlens.app/docs. |
jamesfredley
left a comment
There was a problem hiding this comment.
The items this review found have been addressed. An alias declared inside a block is continued, and a colliding name is refused.
A path given to
createAliason aDetachedCriteriaor awherequery that starts with an alias declared earlier now continues the path of that alias: aftercreateAlias('children', 'c'), the pathc.relatedischildren.related. Before, such a call failed with aQueryExceptionor 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
AbstractDetachedCriteriaonly. The rest of #16890 (theMultipleAliasesMappingContextopt-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) andgrails-data-hibernate5-core(691 tests) pass, andcodeStyleis clean.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