I'm testing the new JPA 2.1 Type Converters. I want to avoid NULL String values to be stored in a legacy database as they are not allowed. So I defined the following converter:
@Converter(autoApply=true)
public class CString implements AttributeConverter<String, String> {
@Override
public String convertToDatabaseColumn(String str) {
if( str == null || str.length() == 0 ) {
return " ";
} else {
return str;
}
}
@Override
public String convertToEntityAttribute(String str) {
if( str == null || str.length() == 0 || str.equals(" ") ) {
return null;
} else {
return str;
}
}
}
String properties should be converted to a space character if they are NULL, but the converter method's are not executed when the properties are NULL.
I'm trying hibernate-jpa-2.1-api (1.0.0.Final) and hibernate-entitymanager (4.3.6.Final).
Is there any JPA 2.1 compliant way to get around this?