Reputation: 6979
Regarding the JdbcTemplate, I'm using this code to retrieve the resultset:
List<Book> bookList = jdbcTemplate.query(
constructQueryStatement(),
new Object[] {row_start, row_end},
new BookRowMapper());
Anyhow, the above code is giving me this warning:
Type safety: The expression of type List needs unchecked conversion to conform to List<Book>
I think this warning is come from the jdbcTemplate.query() is returning a list of Type
that is unknown to List<Book>
. Is there a way to over come this warning beside using @SuppressWarnings 'unchecked'
?
Upvotes: 3
Views: 3050
Reputation: 3926
Work for me.
I use BeanPropertyRowMapper
I don't like use @SuppressWarnings 'unchecked', If really need.
List<Book> resultList = jdbcTemplate.query(sql.toString(), new BeanPropertyRowMapper<Book>(Book.class));
if (!resultList.isEmpty()) {
return resultList;
}
return null;
Result: List for object book.
Upvotes: 3
Reputation: 4425
If you upgrade to Spring 3.0 or later, both JdbcTemplate.query() and RowMapper have been parameterized. Thus you will be able to fully utilise generics without receiving any compiler warnings.
Upvotes: 3