#2199 - ScalarTypeWrapper doesn't handle "nullValue" correctly

Fix for - standard JPA AttributeConverter which doesn't have the getNullValue method, he/she can't convert null to a custom null object

AttributeConverterAdapter probes the AttributeConverter for the nullValue rather than just assuming it is null.
This commit is contained in:
Robin Bygrave
2021-03-18 16:14:46 +13:00
parent 2e16f05a70
commit bb73c30bb7
2 changed files with 73 additions and 1 deletions
@@ -10,14 +10,24 @@ import javax.persistence.AttributeConverter;
class AttributeConverterAdapter<B,S> implements ScalarTypeConverter<B, S> {
private final AttributeConverter<B,S> converter;
private final B nullValue;
AttributeConverterAdapter(AttributeConverter<B, S> converter) {
this.converter = converter;
this.nullValue = probeNullValue();
}
private B probeNullValue() {
try {
return converter.convertToEntityAttribute(null);
} catch (Exception e) {
return null;
}
}
@Override
public B getNullValue() {
return null;
return nullValue;
}
@Override