Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enum arguments with value null do not use type VARCHAR #1414

Closed
rherrmann opened this issue Jan 15, 2019 · 4 comments
Closed

Enum arguments with value null do not use type VARCHAR #1414

rherrmann opened this issue Jan 15, 2019 · 4 comments
Labels
Milestone

Comments

@rherrmann
Copy link
Contributor

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?

@leaumar
Copy link

leaumar commented Jan 15, 2019

We're actually working on an enum handling renovation right now. We'll account for this issue in the changes :)

@stevenschlansker
Copy link
Member

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.

@stevenschlansker stevenschlansker added this to the Next Release milestone Jan 23, 2019
@stevenschlansker
Copy link
Member

stevenschlansker commented Jan 24, 2019

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)

@rherrmann
Copy link
Contributor Author

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!

@leaumar leaumar closed this as completed Jan 27, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

3 participants