带 Oracle 的 ZonedDateTime

ZonedDateTime with Oracle

我正在尝试将 ZonedDateTime 持久保存到 Oracle。以下是我的域实体 class:

@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

如果有人能帮助我解决我做错的地方,将不胜感激。

在您的实体 class.

的 createdOn 属性之上添加 @Convert(converter=OracleZonedDateTimeSeriliazer.class)