1
我做了一個轉換器,當我從數據庫中讀取日期字段時,它應該能夠強制它們到java.time.LocalDate
對象。然而,當我嘗試這樣做,它給了我這個錯誤:JPA轉換器從日期到java.time.LocalDate不適用Glassfish 4.1
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
是我的表,其中有一列START_DATE
這是DATE
類型。這裏是轉換器:
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);
}
}
爲什麼它認爲我的專欄是時間戳?在oracle中的所有日期都被強制爲java.sql.Timestamp
?