Jdbi: Not updated row.wasNull value

Created on 15 Oct 2018  路  5Comments  路  Source: jdbi/jdbi

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

All 5 comments

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 ;)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

qualidafial picture qualidafial  路  3Comments

jarlah picture jarlah  路  3Comments

stevenschlansker picture stevenschlansker  路  4Comments

agavrilov76 picture agavrilov76  路  5Comments

keith-miller picture keith-miller  路  3Comments