3

我正在尝试将 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

如果有人可以帮助我做错了什么,将不胜感激。

4

1 回答 1

1

在您的实体类的 createdOn 属性之上添加 @Convert(converter=OracleZonedDateTimeSeriliazer.class) 。

于 2016-12-19T11:53:46.857 回答