Skip to content

fix(datastore): a subquery in updateAll or deleteAll takes its parameters in order and joins its criteria with AND - #17049

Open
borinquenkid wants to merge 1 commit into
7.0.xfrom
fix/bulk-statement-subquery-7.0.x
Open

borinquenkid wants to merge 1 commit into
7.0.xfrom
fix/bulk-statement-subquery-7.0.x

Conversation

@borinquenkid

Copy link
Copy Markdown
Member

The subquery of an inList or notIn criterion in the bulk statements of updateAll and deleteAll is written by JpaQueryBuilder in the datastore core, for Hibernate 5 on 7.x:

  • a criterion after the subquery failed with IllegalArgumentException: Could not locate named parameter [p3], expecting one of [p1, p2], because the parameter position did not advance past the parameters the subquery added;
  • the criteria of a subquery were written one after the other with no AND between them;
  • a subquery without criteria was written with a WHERE and nothing after it.

The position now continues from the number of parameters after a subquery, in the In handler and in handleSubQuery, and the criteria of a subquery are joined as a conjunction, with no WHERE when there are none. WhereQuerySubqueryBulkSpec has four features for updateAll and deleteAll; all four fail without the change.

This is the subquery part of #16816, split out because it fixes a call that throws on Hibernate 5 today and does not depend on the where-query functions (matrei's review of #16816). Merging 7.0.x up will conflict with the same lines in #16816, which keeps the rest; the version of this change in #16816 is a superset and should be kept.

Local verification: the tests of grails-datastore-core, grails-datamapping-core and grails-data-hibernate5-core pass, and codeStyle passes.

https://claude.ai/code/session_01Dmki4RzWwreEC2GkkyFnvL

…ters in order, joins its criteria with AND and has no WHERE without criteria

JpaQueryBuilder wrote the subquery of an inList or notIn criterion into the bulk statements of updateAll and deleteAll
without advancing the parameter position past the parameters it added, so a criterion after it failed with
"Could not locate named parameter [p3], expecting one of [p1, p2]". It also wrote the criteria of a subquery one after
the other with no AND between them, and wrote WHERE for a subquery that has no criteria, which is not valid.

The position continues from the number of parameters after a subquery, in the In handler and in handleSubQuery, and
the criteria of a subquery are joined as a conjunction, with no WHERE when there are none.

Claude-Session: https://claude.ai/code/session_01Dmki4RzWwreEC2GkkyFnvL
Copilot AI balanced review requested due to automatic review settings November 18, 2026 23:50

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 19, 2026

Copy link
Copy Markdown

✅ All tests passed ✅

🏷️ Commit: fae8073
▶️ Tests: 58156 executed
⚪️ Checks: 58/58 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.

Reviewed at fae8073 (base 7.0.x). It merges cleanly with the current 7.0.x (aee4c04).

Thanks for splitting this out of #16816.

Verified as correct

  • Each shape the change fixes throws on 7.0.x today, so no result changes without an error and no upgrade note is needed. With the head's JpaQueryBuilder the four features of WhereQuerySubqueryBulkSpec pass. With 7.0.x's, all four fail:

    Feature 7.0.x
    A criterion after the subquery, updateAll Could not locate named parameter [p3], expecting one of [p1, p2]
    Two criteria in the subquery QuerySyntaxException: unexpected AST node: <=
    A subquery without criteria QuerySyntaxException: unexpected token: )
    A criterion after the subquery, deleteAll Could not locate named parameter [p2], expecting one of [p1]
  • Every subquery handler gets the position fix. NotIn and the …All and …Some comparisons go through handleSubQuery, which now returns parameters.size(), and the In handler, which calls buildSubQuery itself, continues from it too.

  • The position and the parameter count are equal wherever a subquery starts. The WHERE clause starts from parameters.size(), after the SET values of updateAll, and each handler adds one parameter per position.

  • The fix reaches updateAll and deleteAll only. On 7.0.x, HibernateSession's bulk statements are the only users of JpaQueryBuilder.

  • The merge-up is clean. The change applies cleanly to JpaQueryBuilder on 7.1.x, 7.2.x and 8.0.x. The conflict the description mentions is #16816's, when it next merges 8.0.x. #16816 makes the same changes in those places, so keeping its version there is right.

  • CI passes on this head.

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