Closed
Description
Affects: spring-jdbc
5.3.3
We have the following code:
return jdbcTemplate.query("SELECT whatever FROM table WHERE id IN (:ids)",
new MapSqlParameterSource("ids",
new SqlParameterValue(BIGINT, orders.stream().map(Order::getOrderId)
.collect(Collectors.toSet()))),
rs -> {
// elided...
});
... Spring correctly identifies the parameter value as Iterable
and replaces the :ids
with the correct number of question marks.
But here
Spring does not correctly identify the value as an Iterable. This is because a few lines earlier
... Spring unwraps the SqlParameterValue
, but its content is just another SqlParameterValue
which contains the actual Iterable
.
We can use the following code to circumvent the problem:
return jdbcTemplate.query("SELECT whatever FROM table WHERE id IN (:ids)",
new MapSqlParameterSource()
.addValue("ids", orders.stream().map(Order::getOrderId)
.collect(Collectors.toSet())),
rs -> {
// elided...
});