Repository navigation
fix(datastore): a subquery in updateAll or deleteAll takes its parameters in order and joins its criteria with AND - #17049
borinquenkid wants to merge 1 commit into
Conversation
…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
✅ All tests passed ✅🏷️ Commit: fae8073 Learn more about TestLens at testlens.app/docs. |
matrei
left a comment
There was a problem hiding this comment.
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
JpaQueryBuilderthe four features ofWhereQuerySubqueryBulkSpecpass. With 7.0.x's, all four fail:Feature 7.0.x A criterion after the subquery, updateAllCould 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, deleteAllCould not locate named parameter [p2], expecting one of [p1] -
Every subquery handler gets the position fix.
NotInand the…Alland…Somecomparisons go throughhandleSubQuery, which now returnsparameters.size(), and theInhandler, which callsbuildSubQueryitself, continues from it too. -
The position and the parameter count are equal wherever a subquery starts. The
WHEREclause starts fromparameters.size(), after theSETvalues ofupdateAll, and each handler adds one parameter per position. -
The fix reaches
updateAllanddeleteAllonly. On 7.0.x,HibernateSession's bulk statements are the only users ofJpaQueryBuilder. -
The merge-up is clean. The change applies cleanly to
JpaQueryBuilderon 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.
The subquery of an
inListornotIncriterion in the bulk statements ofupdateAllanddeleteAllis written byJpaQueryBuilderin the datastore core, for Hibernate 5 on 7.x: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;ANDbetween them;WHEREand nothing after it.The position now continues from the number of parameters after a subquery, in the
Inhandler and inhandleSubQuery, and the criteria of a subquery are joined as a conjunction, with noWHEREwhen there are none.WhereQuerySubqueryBulkSpechas four features forupdateAllanddeleteAll; 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-coreandgrails-data-hibernate5-corepass, andcodeStylepasses.https://claude.ai/code/session_01Dmki4RzWwreEC2GkkyFnvL