I get the error “JDBCExceptionReporter – incompatible data types in combination” when running the following code:
public Collection<SensorReading> getLastReadings(int[] sensorIds)
throws DataAccessException {
StringBuilder sb = new StringBuilder();
sb.append("SELECT r ");
sb.append("FROM Sensor AS s, SensorReading AS r ");
sb.append("WHERE s.id IN (");
for(int sensId:sensorIds){
sb.append("'");
sb.append(sensId);
sb.append("',");
}
//strip off the last comma
sb.setLength(sb.length() -1);
//build the rest of the query
sb.append(") AND s.id = r.sensorId ");
sb.append(" AND r.readingTimestampUtc >= s.lastBeaconUtc ");
List<SensorReading> readings = getHibernateTemplate().find(sb.toString());
//map to hold only the latest result
Map<Integer, SensorReading> readingsMap = new HashMap<Integer, SensorReading>();
//flash through the readings and make sure there's only one per sensor ID
for(SensorReading rdg:readings){
Integer sensorId = rdg.getSensorId();
SensorReading reading = readingsMap.get(sensorId);
if(reading==null){
readingsMap.put(sensorId, rdg);
}
else{
//replace if the new reading is later
if(reading.getReadingTimestampUtc().after(rdg.getReadingTimestampUtc())){
readingsMap.put(sensorId, reading);
}
}
}
return readingsMap.values();
}
sensor id and sensorreading sensorid are all integers and the other joins are dates. Any ideas why i might be getting this?
Yikes! The problem was the quotes around the IDs in the list.
Why doesn’t hibernate deal with this properly?