Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between BeanPropertyRowMapper and ParameterizedBeanPropertyRowMapper?

I just started to learn Spring (3.2.8) and come across this question:

NamedParameterJdbcTemplate jdbc = (NamedParameterJdbcTemplate)ctx.getBean("namedjdbc");

Map<String, Object> params = new HashMap<String, Object>();
params.put("rownum", 10);
params.put("variablename", "FlyMark");

List<Variable> variables = jdbc.query(
        "select materialname, variablename, variablevalue " +
        "from tbl_variables " +
        "where variablename = :variablename and rownum < :rownum",
        params,
        //BeanPropertyRowMapper.newInstance(Variable.class)
        ParameterizedBeanPropertyRowMapper.newInstance(Variable.class)
        );

It seems if I replace ParameterizedBeanPropertyRowMapper with BeanPropertyRowMapper, it works too and nothing different.

So my question is: what is ParameterizedBeanPropertyRowMapper designed for?

like image 743
neolei Avatar asked Oct 21 '22 12:10

neolei


1 Answers

As of Spring 3.0 the ParameterizedBeanPropertyRowMapper and BeanPropertyRowMapper are the same.

The ParameterizedBeanPropertyRowMapper (actually everything in the org.springframework.jdbc.core.simple package) was added in the time that Spring was compatible with java version < 1.5 which didn't had generics. To work around this restriction basically 2 implementations of classes started to emerge (one with and one without generics).

As of Spring 3.0 the minimum supported java version has been brought back to 1.5 and as such the seperate packages where merged into the core of the framework and made those parameterized versions obsolote. Most of the code (for instance SimpleJdbcTemplate) is deprecated or at least should be considered deprecated. They are still there for backwards compatibility but will probably be removed in the next major release of Spring.

Links

  1. ParameterizedRowMapper
  2. SimpleJdbcTemplate
like image 88
M. Deinum Avatar answered Oct 29 '22 16:10

M. Deinum