Check condition for BooleanJavaType limit char to Boolean converter

Hi,
While upgrading to Hibernate 6, we are limited by the BooleanJavaType check condition.
We want to convert Boolean to char as follows:

  • Boolean.TRUE => ‘Y’
  • Boolean.FALSE => ‘N’
  • Null => ‘X’

Our Converter:

public class CustomCharBooleanConverter extends CharBooleanConverter {
    public static final CustomCharBooleanConverter INSTANCE = new CustomCharBooleanConverter();

    private static final String[] VALUES = {"Y", "N", "X"};

    @Override
    protected String[] getValues() {
        return VALUES;
    }

    @Override
    public Boolean toDomainValue(Character relationalForm) {
        if ( relationalForm == null ) {
            return null;
        }
        switch ( relationalForm ) {
            case 'Y':
                return true;
            case 'N':
                return false;
        }
        return null;
    }

    @Override
    public Character toRelationalValue(Boolean domainForm) {
        if ( domainForm == null ) {
            return 'X';
        }
        return domainForm ? 'Y' : 'N';
    }
}

we get constraint for the annotated field :
field bpchar check (field in ('N','Y'))
It seems that check condition for BooleanJavaType ignore null value and we get check constraint violation PSQLException error.

Hi @Thara, this is a valid point - we could also include the null value in the check condition if the boolean-converted column is nullable. Please create a new ticket in our issue tracker with a simple reproducer test case to keep track of this.

Thank @mbladel
Here’s the ticket [HHH-18451]

1 Like