Hey, I have caught shady case. Bean in BeanMapper has NULL instead of exists byte[] value.
MySQL database table:
b_column varchar(10), /* value = NULL */
c_column longblob, /* value = some value */
Java object:
String b_column; // NULL - it's okay
byte[] c_column; // NULL - why?
As I have debugged BuiltInMapperFactory:
private static <T> ColumnMapper<T> referenceMapper(ColumnGetter<T> getter) {
return (r, i, ctx) -> {
T value = getter.get(r, i); // value = byte[..] - not null, it's okay
return r.wasNull() ? null : value; // r.wasNull() = true - why true?
};
}
If I set b_column value, it works fine.
Can someone explain this case please?
Version: org.jdbi:jdbi3-core:3.5.1
The r is a ResultSet, which AFAIK comes from your jdbc database library... So if it misbehaves, I think the problem lies in that. On sight, this code in jdbi looks fine to me, though using wasNull instead of just == null is kinda odd to my mind. Maybe to handle something like Null Objects where a regular null check would mislead you.
referenceMapper is used for wrapped primitives like Integer.class. JDBC ResultSet only provides a getInt(column) method, which returns a primitive int. If the column is null, 0 is returned. So you _must_ call wasNull() after the fact to know whether the column was actually null.
Handy knowledge, thanks
@Romqa which JDBC driver are you using?
@qualidafial, yeap, problem was in mysql-connector, thank you ;)