-
Notifications
You must be signed in to change notification settings - Fork 83
Closed
Labels
Description
My entity contains a property with a jpa-converter which converts a string db value to boolean. If I filter on that specific property like e.g. $filter=active eq true the value true won't get converted back to String which results in a SQL-Error.
The problem is in com.sap.olingo.jpa.processor.cb.impl.ExpressionImpl.ParameterExpression.setPath.The property 'converter' will be set with an empty Optional, because jpaPath.get().getLeaf().getConverter() returns null, because conversionRequired is false. It is false, because boolean is a olingo supported datatype if I remember correctly.
void setPath(@Nullable final Expression<?> expression) {
if (expression instanceof PathImpl && ((PathImpl<?>) expression).path.isPresent()) {
jpaPath = Optional.of(((PathImpl<?>) expression).path.get()); // NOSONAR
converter = Optional.ofNullable(jpaPath.get().getLeaf().getConverter());
} else {
this.converter = Optional.empty();
this.jpaPath = Optional.empty();
}
}
if I change it to getRawConverter() everything works perfectly fine.
Here is the entity:
@Entity
@Table(name = "A_TEST")
public class Test implements Retraceable, Versionable
{
@Convert(converter = Converters.JPA.BooleanToYN.class)
@Column(name = "ACTIVE")
private Boolean active;
}
Here is the converter:
public static final class BooleanToYN implements AttributeConverter<Boolean, Character>
{
@Override
public Character convertToDatabaseColumn(Boolean attribute)
{
if (attribute == null)
return null;
return Boolean.TRUE.equals(attribute) ? 'Y' : 'N';
}
@Override
public Boolean convertToEntityAttribute(Character dbData)
{
if (dbData == null)
return null;
return dbData.equals('Y');
}
}