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 に答える