Skip to content

Add option to parse named parameters in SQL comments - #37088

Open
benelog wants to merge 1 commit into
spring-projects:mainfrom
benelog:gh-22255
Open

Add option to parse named parameters in SQL comments#37088
benelog wants to merge 1 commit into
spring-projects:mainfrom
benelog:gh-22255

Conversation

@benelog

@benelog benelog commented Jul 26, 2026

Copy link
Copy Markdown
Contributor

This PR introduces:

  • NamedParameterUtils.parseSqlStatement(String, boolean) with an allowParametersInComments flag
  • a corresponding allowParametersInComments property on NamedParameterJdbcTemplate (default false, preserving the current behavior)

Even with the flag enabled, string literals and quoted identifiers are still skipped. Changing the flag resets the template's parsed SQL cache, so previously parsed statements are re-parsed with the new setting.

Closes gh-22255

By default, named parameters within SQL comments are ignored. Some
database engines interpret hints or routing keys declared in comments,
for example "/*@ queryKey(:userId) */ SELECT ...", requiring such
parameters to be substituted and bound as well.

This commit introduces a parseSqlStatement variant with an
allowParametersInComments flag in NamedParameterUtils as well as a
corresponding allowParametersInComments property on
NamedParameterJdbcTemplate.

Closes spring-projectsgh-22255

Signed-off-by: Sanghyuk Jung <sanghyuk.jung@navercorp.com>
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Jul 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status: waiting-for-triage An issue we've not yet triaged or decided on

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow NamedParameterJdbcTemplate to optionally include parameters in comments of SQL

2 participants