I’m developing a web application using Spring 3.1.2, and need to create a custom row mapper. I have created a private static final class which implements RowMapper, but i’m getting the error message “The type RowMapper is not generic; it cannot be parameterized with arguments “.
All Spring related jars in my lib folder are of 3.1.2.RELEASE version. I have been unable to find anything of the sort elsewhere. Any ideas why this might be happening?
Thanks.
Here is the sample code:
public class OutPatient extends Patient{
@Pattern(regexp="[0-9]+", message="OPD No. should only contain digits.")
String opdNo;
public String getOpdNo() {
return opdNo;
}
public void setOpdNo(String opdNo) {
this.opdNo = opdNo;
}
}
DAO Class:
@Repository("dbHelper")
public class DBHelperImpl{
private JdbcTemplate jdbcTemplate;
private NamedParameterJdbcTemplate namedParameterJdbcTemplate;
@Autowired
public void setDataSource(DataSource dataSource) {
this.jdbcTemplate = new JdbcTemplate(dataSource);
this.namedParameterJdbcTemplate = new NamedParameterJdbcTemplate(dataSource);
}
public List<OutPatient> fetchOutPatients() {
String sql = "SELECT OPDNO as opdNo FROM `test`.`out_patient`";
@SuppressWarnings("unchecked") //Have to add this annotation to prevent warning
List<OutPatient> outPatients = jdbcTemplate.query(sql, new OutPatientRowMapper());
return outPatients;
}
private static final class OutPatientRowMapper implements RowMapper{ //Unable to add <OutPatient> generics here!
public OutPatient mapRow(ResultSet rs, int rowNum) throws SQLException {
OutPatient outPatient = new OutPatient();
outPatient.setOpdNo(rs.getString("opdNo"));
return outPatient;
}
}
I found the solution to my problem after tinkering around a bit more. There were some old spring jars (2.0, I guess) in Tomcat’s lib folder. That led to spring using an older version of RowMapper which didnot support parameterization.
Solution to this problem is either remove the older jars from the build path, or to change the order of the jars from the Order and Export tab and bring the latest jar to the top.
Thanks to all those who responded!