GlobalDictator
asked on
jdbcTemplate.query(String sql, RowMapper<?> rowMapper, Object[] args) returns an error when a field is null
Hi,
Further to my last question, I'm getting an error when one of the mapped fields is null.
Is there a way that I can make the RowMapper to accept or ignore nulls?
Thanks
Further to my last question, I'm getting an error when one of the mapped fields is null.
List<DelConversation> delConversations = jdbcTemplate.query(
SELECT_ALL_CONVERSATIONS_SQL,
new Object[] {dateFrom, dateTo}, new BeanPropertyRowMapper(DelConversation.class));
Is there a way that I can make the RowMapper to accept or ignore nulls?
Thanks
Please post the error
ASKER
org.springframework.beans.TypeMismatchException: Failed to convert property value of type [null] to required type [long] for property 'leftdate'; nested exception is java.lang.IllegalArgumentException: Cannot convert value of type [null] to required type [long] for property 'leftdate': PropertyEditor [org.springframework.beans.propertyeditors.CustomNumberEditor] returned inappropriate value
The DB field 'LeftDate' is empty in the DB, so I suppose thats whats causing he problem. When that field is populated, then there are no issues..
From the API docs:
"For 'null' values read from the databasem, we will attempt to call the setter, but in the case of Java primitives, this causes a TypeMismatchException. This class can be configured (using the primitivesDefaultedForNull Value property) to trap this exception and use the primitives default value. Be aware that if you use the values from the generated bean to update the database the primitive value will have been set to the primitive's default value instead of null."
"For 'null' values read from the databasem, we will attempt to call the setter, but in the case of Java primitives, this causes a TypeMismatchException. This class can be configured (using the primitivesDefaultedForNull
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
@Yan,
Thanks very much for the practical demonstration of how to use the 'primitivesDefaultedForNul lValue' property.
I'll implement this and let you know of the outcome.
Thanks
Thanks very much for the practical demonstration of how to use the 'primitivesDefaultedForNul
I'll implement this and let you know of the outcome.
Thanks
GlobalDictator, can you tell me why you ignored my comment, which explained the problem?
ASKER
@CEHJ
Sorry for the late reply. I didnt ignore your comment but Yan's response was much more helpful due to the actual example.
Sorry for the late reply. I didnt ignore your comment but Yan's response was much more helpful due to the actual example.