-
Notifications
You must be signed in to change notification settings - Fork 38.7k
Closed
Labels
in: dataIssues in data modules (jdbc, orm, oxm, tx)Issues in data modules (jdbc, orm, oxm, tx)type: enhancementA general enhancementA general enhancement
Milestone
Description
Affects: 4.3.18
When specifying named parameters and using a NamedParameterJdbcTemplate
, if you want to replace an "IN" clause argument with a series of values you must supply a Collection
.
Example:
Map<String, ?> params = new HashMap<>();
params.put("ages", Arrays.asList("30", "31");
template.queryForList("SELECT name FROM Person WHERE age IN (:ages)", params, String.class);
This will translate to: SELECT name FROM Person WHERE age IN (?, ?)
with those "?" replaced with 30 and 31 respectively.
If, however, you specify ages
param as an array, or as some other kind of Iterable
, this does not work: the parameter is translated into a single String SQL param value using the array or Iterable
toString()
output.
IMHO this is not intuitive, especially if you're using an array (an array of enum values, for instance). It took me quite a lot today to discover why a query was not producing the expected results.
Metadata
Metadata
Assignees
Labels
in: dataIssues in data modules (jdbc, orm, oxm, tx)Issues in data modules (jdbc, orm, oxm, tx)type: enhancementA general enhancementA general enhancement