I have made a converter such that when I read DATE fields out of the database, it should be able to coerce them to java.time.LocalDate
objects. However, when I try to do so, it gives me this error:
The object [3/16/17 12:00 AM], of class [class java.sql.Timestamp], from mapping [org.eclipse.persistence.mappings.DirectToFieldMapping[startDate-->TEST_TABLE.START_DATE]] with descriptor [RelationalDescriptor(com.test.TestEntity --> [DatabaseTable(TEST_TABLE)])], could not be converted to [class [B].
TEST_TABLE
is my table, which has a column START_DATE
which is of type DATE
. Here is the converter:
import javax.persistence.AttributeConverter;
import javax.persistence.Converter;
import java.sql.Date;
import java.time.LocalDate;
@Converter(autoApply = true)
public class OracleLocalDateAttributeConverter implements AttributeConverter<LocalDate, Date> {
@Override
public Date convertToDatabaseColumn(LocalDate attribute) {
return (attribute != null ? Date.valueOf(attribute) : null);
}
@Override
public LocalDate convertToEntityAttribute(Date dbData) {
return (dbData != null ? dbData.toLocalDate() : null);
}
}
Why does it think that my column is a timestamp? Do all dates in oracle get coerced to java.sql.Timestamp
?