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.