2
私はZonedDateTimeをOracleに永続化しようとしています。以下は、私のドメインエンティティクラスです:ZonedDateTime with 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
私が間違っていることを誰かが助けてくれたら、それは大歓迎です。
おそらく、 'java.util.Date'ではなく' java.sql.Timestamp'に変換することをお勧めします。これは 'java.util.Date'がJDBC APIでサポートされていないため、コンバータは呼び出されず、 'ZonedDateTime'はバイトに「カスタム」Javaクラスとしてシリアライズされます。もちろん、 'hibernate-java8'も含めることができます。http://stackoverflow.com/a/33001846/5221149 – Andreas
" CREATE_DATE "のDB-column-typeとは何ですか? –
@MenoHochschildそのDATEはsql.Date – Gurkha