Skip to content

Use SqlParameterSource as-is in SqlParameterSourceUtils.createBatch() - #37524

Merged
sbrannen merged 1 commit into
spring-projects:mainfrom
lejuho:sqlparametersourceutils-createbatch-passthrough
Oct 20, 2026
Merged

sbrannen merged 1 commit into
spring-projects:mainfrom
lejuho:sqlparametersourceutils-createbatch-passthrough

Conversation

@lejuho

@lejuho lejuho commented Oct 20, 2026

Copy link
Copy Markdown
Contributor

SqlParameterSourceUtils.createBatch(Collection) (and the createBatch(Object...) variant that delegates to it) wraps every candidate that is not a Map in a BeanPropertySqlParameterSource. An SqlParameterSource passed in, for example a MapSqlParameterSource built for one batch entry, is then read through its own bean properties (values, parameterNames, ...) instead of its parameter values, so NamedParameterJdbcTemplate.batchUpdate fails with "No value supplied for the SQL parameter".

This change returns such a candidate as-is, the same way JdbcClient now resolves paramSource(Object) and its batch entries (gh-37501), and mentions it in the Javadoc of both createBatch variants.

SqlParameterSourceUtilsTests is new, as createBatch had no tests. It covers a mixed batch of a Map, a bean and an SqlParameterSource, and the varargs variant. Both tests fail without the change.

./gradlew :spring-jdbc:test --tests 'org.springframework.jdbc.core.namedparam.*' :spring-jdbc:checkstyleMain :spring-jdbc:checkstyleTest passes.

SqlParameterSourceUtils.createBatch wraps every candidate that is not
a Map in a BeanPropertySqlParameterSource, so an SqlParameterSource
passed in is exposed through its own bean properties instead of its
parameter values.

This commit returns such a candidate as-is, as JdbcClient now does
for paramSource(Object) and its batch entries.

Signed-off-by: lejuho <zedd1324@gmail.com>
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Oct 20, 2026
@sbrannen sbrannen added the in: data Issues in data modules (jdbc, orm, oxm, tx) label Oct 20, 2026
@sbrannen sbrannen self-assigned this Oct 20, 2026
@sbrannen sbrannen changed the title Use SqlParameterSource as-is in SqlParameterSourceUtils.createBatch Use SqlParameterSource as-is in SqlParameterSourceUtils.createBatch() Oct 20, 2026
@sbrannen sbrannen added type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Oct 20, 2026
@sbrannen sbrannen added this to the 7.1.0-RC2 milestone Oct 20, 2026
@sbrannen
sbrannen merged commit a38ebf4 into spring-projects:main Oct 20, 2026
5 checks passed
@sbrannen

Copy link
Copy Markdown
Member

This has been merged into main.

Thanks

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

Labels

in: data Issues in data modules (jdbc, orm, oxm, tx) type: enhancement A general enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants