'Spring RowMapper is being ignored
I am calling my stored procedure like that:
SimpleJdbcCall jdbcCall = new SimpleJdbcCall(jdbcTemplate)
.returningResultSet("LookupResponse", new LookupMapper())
.withProcedureName(lookupProcedureName);
and pass some parameters:
SqlParameterSource in = new MapSqlParameterSource()
.addValue("id", request.getId())
.addValue("Username", userName)
Code of the row mapper:
public class LookupMapper implements RowMapper<LookupResponse> {
@Override
public LookupResponse mapRow(ResultSet rs, int i) throws SQLException {
LookupResponse lookupResponse = new LookupResponse();
lookupResponse.setDeviceId(rs.getInt("DeviceId"));
lookupResponse.setApplicationId(rs.getInt("AppId"));
return lookupResponse;
}
}
Then I call the DB:
Map<String, Object> out = jdbcCall.execute(in);
I see unmapped key-value pairs in the returned map, and when I do:
(Collection<LookupResponse>) out.get("LookupResponse");
it returns null.
There is no key with my row mapped response. The same kind of code works with another stored procedure... I don't understand what might be the reason. No exceptions in console, the rowMapper just being ignored. Please, help me understand.
Solution 1:[1]
Change as per below
Map<String, Object> out = jdbcCall.execute(in);
to
Map<String, Object> outMap = jdbcCall.withReturnValue().execute(in);
Solution 2:[2]
I had the same problem. Do this to troubleshoot
System.out.println(out);
Make sure the string starts with "LookupResponse"
{LookupResponse=[...
if not replace it accordingly
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Jaganath Kamble |
| Solution 2 | Arya |
