繁体   English   中英

未找到请求操作的编解码器:[日期 <-> java.util.Date]

[英]Codec not found for requested operation: [date <-> java.util.Date]

在 Cassandra 中,列类型设置为 Date,在 Model 类中,字段类型设置为 java.util.Date,并带有 getter 和 setter。 com.datastax.driver.mapping.Mapper.save我得到以下异常:

Codec not found for requested operation: [date <-> java.util.Date]

Caused by: com.datastax.driver.core.exceptions.CodecNotFoundException: Codec not found for requested operation: [date <-> java.util.Date]
at com.datastax.driver.core.exceptions.CodecNotFoundException.copy(CodecNotFoundException.java:56)
at com.datastax.driver.core.exceptions.CodecNotFoundException.copy(CodecNotFoundException.java:25)
at com.datastax.driver.mapping.DriverThrowables.propagateCause(DriverThrowables.java:41)
at com.datastax.driver.mapping.Mapper.save(Mapper.java:272)

在 Google 搜索过程中发现以下内容:

DATE      <-> com.datastax.driver.core.LocalDate : use getDate()

您必须将 java.util.Date 转换为com.datastax.driver.core.LocalDate

例子:

 LocalDate localDate = LocalDate.fromMillisSinceEpoch(date.getTime());

我在使用时间戳时遇到了同样的问题

reactor.core.Exceptions$ErrorCallbackNotImplemented: com.datastax.oss.driver.api.core.type.codec.CodecNotFoundException: Codec not found for requested operation: [TIMESTAMP <-> java.util.Date]
Caused by: com.datastax.oss.driver.api.core.type.codec.CodecNotFoundException: Codec not found for requested operation: [TIMESTAMP <-> java.util.Date]
    at com.datastax.oss.driver.internal.core.type.codec.registry.CachingCodecRegistry.createCodec(CachingCodecRegistry.java:609) ~[java-driver-core-4.9.0.jar:na]
    at com.datastax.oss.driver.internal.core.type.codec.registry.DefaultCodecRegistry$1.load(DefaultCodecRegistry.java:95) ~[java-driver-core-4.9.0.jar:na]
    at com.datastax.oss.driver.internal.core.type.codec.registry.DefaultCodecRegistry$1.load(DefaultCodecRegistry.java:92) ~[java-driver-core-4.9.0.jar:na]

从驱动程序 4.0 开始,CQL 类型的时间戳不再映射到java.util.Date ,而是映射到java.time.Instant 使用 Instant 对我有用。

在实体类中将 Date 类型替换为 LocalDate 类型:-

private LocalDate createdDate;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM