When testing a JPA 2.1 Converter, the following exception is thrown:
java.lang.ClassCastException: java.lang.Boolean cannot be cast to java.lang.String at com.acme.entity.util.BooleanTFConverter.convertToEntityAttribute(BooleanTFConverter.java:1)
The converter class is:
package com.acme.entity.util;
import javax.persistence.AttributeConverter;
import javax.persistence.Converter;
@Converter
public class BooleanTFConverter
implements AttributeConverter<Boolean, String> {
@Override
public String convertToDatabaseColumn(Boolean value)
{
return Boolean.TRUE.equals(value) ? "T" : "F";
}
@Override
public Boolean convertToEntityAttribute(String value)
{
return "T".equals(value);
}
}
The use in my entity is:
import javax.persistence.Convert;
import com.acme.entity.util.BooleanTFConverter;
...
@Column(name = "ACCOUNT_UNLOCKED")
@Convert(converter=BooleanTFConverter.class)
private Boolean accountUnlocked = true;
This converter works perfectly in the JPA 2.1 reference implementation (EclipseLink 2.5). I can provide a full Eclipse Kepler project if necessary.
|