我正在尝试将ZonedDateTime持久化到Oracle。以下是我的域实体类:
@Entity
@Table(name = "TESTTABLE")
public class Order {
private static final long serialVersionUID = 1L;
@Type(type = "uuid-binary")
@Column(name = "ID")
private UUID id;
@Column(name = "CREATE_DATE")
private ZonedDateTime createdOn;
..and so on.我还有一个转换器,如下所示来转换日期:
@Converter(autoApply = true)
public class OracleZonedDateTimeSeriliazer implements AttributeConverter<ZonedDateTime,Date>{
@Override
public Date convertToDatabaseColumn(ZonedDateTime attribute) {
return attribute == null ? null : java.util.Date.from(attribute.withZoneSameInstant
(ZoneOffset.UTC).toInstant());
}
@Override
public ZonedDateTime convertToEntityAttribute(Date dbData) {
return dbData == null ? null : ZonedDateTime.ofInstant(dbData.toInstant(), DateUtils.getEasternZoneId());
}
}当我试图持久化这个实体时,我得到了以下堆栈跟踪:
2016-12-16 10:47:06,669 [main] ERROR o.h.e.jdbc.spi.SqlExceptionHelper - ORA-00932: inconsistent datatypes: expected DATE got BINARY
org.springframework.dao.InvalidDataAccessResourceUsageException: could not execute statement; SQL [n/a]; nested exception is org.hibernate.exception.SQLGrammarException: could not execute statement如果有人能帮我做错事,我会很感激的。
发布于 2016-12-19 11:53:46
在实体类的@Convert(converter=OracleZonedDateTimeSeriliazer.class)属性之上添加createdOn。
https://stackoverflow.com/questions/41187924
复制相似问题