You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When working with NamedParameterJdbcTemplate, we typically inject an instance of it in a DAO/Repository and use it in 10-20 methods that require accessing the database.
Most of those methods use parameters (which is why we use a NamedParameterJdbcTemplate). However, among the 20 methods inside my DAO, it's common that I have 3-4 of them that use SQL queries without parameters.
In that case, the syntax could be improved.
We currently do:
return this.namedParameterJdbcTemplate.query(
"SELECT id, name FROM types ORDER BY name", new HashMap<String,Object>(),
ParameterizedBeanPropertyRowMapper.newInstance(Pet.class));
Inside NamedParameterJdbcTemplate, we could create some methods that do not take a HashMap as a parameter. We would then do instead:
return this.namedParameterJdbcTemplate.query(
"SELECT id, name FROM types ORDER BY name", ParameterizedBeanPropertyRowMapper.newInstance(Pet.class));
Note: in the first code sample, replacing the empty HashMap with null is not an option because the method call then becomes ambiguous as 2 methods could be selected.
Michael Isvy opened SPR-10256 and commented
When working with NamedParameterJdbcTemplate, we typically inject an instance of it in a DAO/Repository and use it in 10-20 methods that require accessing the database.
Most of those methods use parameters (which is why we use a NamedParameterJdbcTemplate). However, among the 20 methods inside my DAO, it's common that I have 3-4 of them that use SQL queries without parameters.
In that case, the syntax could be improved.
We currently do:
Inside NamedParameterJdbcTemplate, we could create some methods that do not take a HashMap as a parameter. We would then do instead:
Note: in the first code sample, replacing the empty HashMap with null is not an option because the method call then becomes ambiguous as 2 methods could be selected.
Referenced from: commits 3fa6723
The text was updated successfully, but these errors were encountered: