Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NamedParameterJdbcTemplate: add methods to simplify usage when no parameter is needed [SPR-10256] #14889

Closed
spring-projects-issues opened this issue Feb 4, 2013 · 0 comments
Assignees
Labels
in: data Issues in data modules (jdbc, orm, oxm, tx) type: enhancement A general enhancement
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

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:

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.


Referenced from: commits 3fa6723

@spring-projects-issues spring-projects-issues added the type: enhancement A general enhancement label Jan 11, 2019
@spring-projects-issues spring-projects-issues added this to the 3.2.2 milestone Jan 11, 2019
@sbrannen sbrannen added the in: data Issues in data modules (jdbc, orm, oxm, tx) label Nov 3, 2022
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

No branches or pull requests

3 participants