I'm upgrading a Spring 3 application to Spring 4. My @Repository
has ParameterizedRowMapper
objects to map the SQL results to objects. But since Spring 4 that interface has been deprecated "in favor of the regular SingleColumnRowMapper
". But I use mappers for mapping multiple columns. How am I meant to map multiple columns using SingleColumnRowMapper
? Or am I meant to be doing something completely different?
For example, here is the kind of code I have now:
private static final ParameterizedRowMapper<Thing> THING_ENTRY_MAPPER = new ParameterizedRowMapper<Thing>() {
@Override
public Thing mapRow(ResultSet rs, int rowNum) throws SQLException {
return new Thing(rs.getLong(1), rs.getLong(2), rs.getInt(3));
}
};
@Override
public List<Thing> getThings(
ID id, long start, long end) {
final Map<String, Object> params = new HashMap<String, Object>(4);
putIDParams(params, id);
putTimeRangeParams(params, start, end);
return getNamedParameterJdbcTemplate().query(QUERY_THING, params,
THING_ENTRY_MAPPER);
}
How should I be implementing that kind of functionality now?
The Javadoc seems to be wrong. The Spring Framework designers probably intend use of the RowMapper<Thing>
interface to replace ParameterizedRowMapper<Thing>
. That is, use the base interface.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With