I am implementing a solution here to convert the column 'Y' / 'N' to a boolean:
@Basic(optional = false) @Column(name = "ACTIVE_YN") @Convert(converter = BooleanToStringConverter.class) private Boolean active;
.. and:
@Converter public class BooleanToStringConverter implements AttributeConverter<Boolean, String> { @Override public String convertToDatabaseColumn(Boolean value) { return (value != null && value) ? "Y" : "N"; } @Override public Boolean convertToEntityAttribute(String value) { return "Y".equals(value); } }
The problem is that I cannot use booleans in JPQL. The following code gives the error below:
@Query("select thing from MyThing thing where thing.id = :id and thing.active = true") public MyThing findOneActive(@Param("id") ThingIdEnum id);
Mistake:
java.lang.IllegalArgumentException: Validation failed for query for method public abstract xyzMyThing xyzMyThingRepository.findOneActive(xyzThingIdEnum)! ... Unable to render boolean literal value [select thing from MyThing thing where thing.id = :id and thing.active = true] ... org.hibernate.type.descriptor.converter.AttributeConverterTypeAdapter cannot be cast to org.hibernate.type.LiteralType
java jpa jpql
Chris Williams Sep 19 '16 at 20:06 2016-09-19 20:06
source share