【发布时间】:2016-09-15 16:39:03
【问题描述】:
我无法让 JPA 2.4 中的 @Converter 正常工作。我在here 和here 上关注了示例。当我尝试持久化我的实体时,它失败并出现以下异常。有没有人成功地做到这一点?有什么需要注意的吗?
原因:org.apache.openjpa.persistence.PersistenceException:数据截断:不正确的日期时间值:'\xAC\xED\x00\x05sr\x00\x16org.joda.time.DateTime\xB8
转换器类
@Converter
public class DateTimeConverter implements AttributeConverter<DateTime, Timestamp> {
@Override
public Timestamp convertToDatabaseColumn(DateTime dateTime) {
return new Timestamp(dateTime.getMillis());
}
@Override
public DateTime convertToEntityAttribute(Timestamp date) {
return new DateTime(date);
}
}
而且用法看起来像
@Column(name = "created_on")
@Convert(converter = CustomConverter.class)
private DateTime createdOn;
【问题讨论】:
标签: java mysql jpa-2.0 jodatime