Hi folks,
I recently started using MyBatis and love it compared to the popular ORMs out there! What a breath of fresh air and I so appreciate the work the contributors have put in!
It just took me a long while to debug a TypeHandler that I have written for work in some legacy code. I found the problem affecting me in BaseTypeHandler:
@Override
public T getResult(ResultSet rs, String columnName) throws SQLException {
T result;
try {
result = getNullableResult(rs, columnName);
} catch (Exception e) {
throw new ResultMapException("Error attempting to get column '" + columnName + "' from result set. Cause: " + e, e);
}
if (rs.wasNull()) {
return null;
} else {
return result;
}
}
My TypeHandler DOES trigger rs.wasNull() but also returns a type that it has to get back to the caller. In my mind checking rs.wasNull() is incorrect compared to checking result == null.
Just wanted some input on the logic here.
I overrode the getResult() method to solve my problem, but it seems to me my use case could be a common situation?
- GMK.