找不到请求操作的编解码器:[' org.apache.cassandra.db.marshal.SimpleDateType' < - > com.datastax.driver.core.LocalDate]

时间:2017-07-31 11:35:33

标签: cassandra java-8 entities

我在我的应用程序中使用java8和cassandra。 cassandra表中current_date的数据类型为' date'。 我正在使用实体映射到表值。并且同一字段的实体中的数据类型为com.datastax.driver.core.LocalDate。

当我尝试检索记录时 'Select * from table where current_date='2017-06-06';' 我收到以下错误'

引起:com.datastax.driver.core.exceptions.CodecNotFoundException:Codec 找不到要求的操作: [' org.apache.cassandra.db.marshal.SimpleDateType' < - > com.datastax.driver.core.LocalDate]

1 个答案:

答案 0 :(得分:0)

默认情况下,Java驱动程序会将日期类型映射到com.datastax.driver.core.LocalDate Java type.

如果您需要将日期转换为java.time.LocalDate,那么您需要为项目添加额外内容: 您只能为给定列指定编解码器:

 @Column(codec = LocalDateCodec.class) java.time.LocalDate current_date ;

如果这两个不起作用,请查看代码如何创建会话,群集等以连接到数据库。由于date是cassandra数据类型的新增功能,因此协议版本也会产生影响。 相应地更新版本