I usually do this in my repository package:
public void setDataSource(DataSource dataSource) {
procGetDeviceDetails = new SimpleJdbcCall(dataSource)
.withProcedureName("web_Device_Details")
.returningResultSet("results", BeanPropertyRowMapper.newInstance(Device.class));
}
public Device deviceDetails(Map input) {
Map m = procGetDeviceDetails.execute(input);
List<Device> list = (List<Device>) m.get("results");
if (list.size() > 0) {
return list.get(0);
}
return null;
}
I wish to remove boilerplate in second method so I've switched to executeObject(). I tried this. Both failed.
public Device deviceDetails(Map input) {
Device device = procGetDeviceDetails.executeObject(Device.class, input);
return device;
}
public Device deviceDetails(Map input) {
List<Device> device = procGetDeviceDetails.executeObject(List.class, input);
return device.get(0);
}
Problem is that my device is null. I tried also declaring just Object instead of Device or List and it's still null. What am I doing wrong?
I know that result is correctly mapped into Device class because I see that procGetDeviceDetails (SimpleJdbcCall) has declaredRowParameters equal to {#result-set-1=org.springframework.jdbc.core.BeanPropertyRowMapper@79095fd7} and BeanPropertyRowMapper has mappedClass set to Device.
Seems that generics or something else troubles me. I found example here. https://jira.spring.io/browse/SPR-7270
Thanks!