-
Notifications
You must be signed in to change notification settings - Fork 38.8k
Closed
Labels
in: dataIssues in data modules (jdbc, orm, oxm, tx)Issues in data modules (jdbc, orm, oxm, tx)status: feedback-providedFeedback has been providedFeedback has been providedstatus: supersededAn issue that has been superseded by anotherAn issue that has been superseded by anothertype: regressionA bug that is also a regressionA bug that is also a regression
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
Line 268 in d7e05aa
| if (in instanceof Iterable && declaredParameter.getSqlType() != Types.ARRAY) { |
Spring does not correctly identify the value as an Iterable. This is because a few lines earlier
Lines 254 to 258 in d7e05aa
| if (in instanceof SqlParameterValue) { | |
| SqlParameterValue paramValue = (SqlParameterValue) in; | |
| in = paramValue.getValue(); | |
| declaredParameter = paramValue; | |
| } |
... 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...
});Metadata
Metadata
Assignees
Labels
in: dataIssues in data modules (jdbc, orm, oxm, tx)Issues in data modules (jdbc, orm, oxm, tx)status: feedback-providedFeedback has been providedFeedback has been providedstatus: supersededAn issue that has been superseded by anotherAn issue that has been superseded by anothertype: regressionA bug that is also a regressionA bug that is also a regression