I am having a problem with null enum values and JDBI v3.5.1
The enum is represented as a VARCHAR in the database, just like the default representation recommended by JDBI. If, however, I try to insert a null value through an SqlObject, the null value is set as type OTHER. This causes a type error, at least with an Oracle database.
Looking into BuiltinArgumentFactory (or EnumArgument in master), it seems that null values are always bound with getUntypedNullArgument. I was able to work around this issue by registering a custom ArgumentFactory like this:
@Override
public Optional<Argument> build(Type type, Object value, ConfigRegistry config) {
if (value == null && GenericTypes.getErasedType(type).isEnum()) {
return Optional.of(new NullArgument(Types.VARCHAR));
}
return Optional.empty();
}
Is the current behavior intended? Or would you accept a change to EnumArgument that includes the null-handling as shown in the. custom argument factory?
We're actually working on an enum handling renovation right now. We'll account for this issue in the changes :)
This is definitely a bug, and normally we'd fix it independently of a new feature. But since we already have a PR open that fixes this in addition to other new features, we'll let it get merged in.
hi @rherrmann we've merged some Enum changes ( #1427 ) but I don't personally have an oracle database to test. Can you build jdbi from after that change and verify that we've fixed your issue (and not broken anything else)? Thanks!
(We had to remove Oracle build and tests from main jdbi because of the ridiculous Maven setup required, and Oracle's inability to reliably host their jdbc driver)
I wholeheartedly agree that using using Oracle databases (at least from Java) is best avoided.
However, I've run my tests with JDBI from HEAD against an Oracle database and everything looks good!
Most helpful comment
I wholeheartedly agree that using using Oracle databases (at least from Java) is best avoided.
However, I've run my tests with JDBI from HEAD against an Oracle database and everything looks good!