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

北战南征 提交于 2019-12-02 12:53:23

You need to pass variable with com.datastax.driver.core.LocalDate type instead. See the documentation for mapping between Java type and CQL types. You can use LocalDate from JDK 8, or from Joda time package if you'll use so-called optional codec.

Another possibility is to write date<->java.sql.Date and register it for direct mapping.

Thanks a lot @Alex Ott As you suggested I did below

added another jar

 <dependency>
        <groupId>com.datastax.cassandra</groupId>
        <artifactId>cassandra-driver-extras</artifactId>
        <version>3.7.2</version>
    </dependency>

Before calling save() method i called this

public void registerCodecs() {
    CodecRegistry registry = this.session.getCluster().getConfiguration().getCodecRegistry();
    registry.register(LocalDateCodec.instance);
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!