question

mysub99 avatar image
mysub99 asked Erick Ramirez edited

Spring boot app returns "CodecNotFoundException: Codec not found for requested operation: [DATE <-> com.datastax.driver.core.LocalDate]"

I am facing issue with date datatype, following is my table schema

    CREATE TABLE user (
        name text,
        id text,
        date date,
        division text,
        PRIMARY KEY ((name, id, date), name)

my backend is spring boot with following library's

    compile group: 'com.datastax.oss', name: 'java-driver-core', version: '4.9.0'
    compile group: 'com.datastax.cassandra', name: 'cassandra-driver-extras', version: '3.10.2'
    compile group: 'com.datastax.cassandra', name: 'cassandra-driver-mapping', version: '3.2.0'

i am converting java LocalDate to cassandra LocalDate as per below article :

https://docs.spring.io/spring-data/cassandra/docs/current/reference/html/#reference

also if i directly send java LocalDate both are valid as per Cassandra.

def cassandraLocalDate = com.datastax.driver.core.LocalDate.fromYearMonthDay(year, monthValue, dayOfMonth)

while binding statement i am getting error

 def boundStatement = userExists.bind(name, id, cassandraLocalDate)

error:

com.datastax.oss.driver.api.core.type.codec.CodecNotFoundException: Codec not found for requested operation: [DATE <-> com.datastax.driver.core.LocalDate]

Any help will highly appreciated

Thanks & Regards

java driverspring-boot
10 |1000

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

1 Answer

alexandre.dutra avatar image
alexandre.dutra answered

You are mixing incompatible drivers: the group ID com.datastax.oss is not compatible with the group ID com.datastax.cassandra. What is your Spring Boot version? You should use only the driver/group ID that comes with it.

3 comments Share
10 |1000

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

my spring version is

2.4.6


0 Likes 0 ·

Then the only driver you should use is driver 4.9.0:

https://github.com/spring-projects/spring-boot/blob/v2.4.6/spring-boot-project/spring-boot-dependencies/build.gradle#L163

You probably don't need these two, and I suggest that you remove them from your project:

  • compile group: 'com.datastax.cassandra', name: 'cassandra-driver-extras', version: '3.10.2'

  • compile group: 'com.datastax.cassandra', name: 'cassandra-driver-mapping', version: '3.2.0'

As for the usage of LocalDate with driver 4.9, the guide you followed is not up-to-date. Please read this instead:

https://docs.datastax.com/en/developer/java-driver/4.9/manual/core/temporal_types/

1 Like 1 ·
mysub99 avatar image mysub99 alexandre.dutra ♦ ·
thanks i removed other two drivers and its working fine now
0 Likes 0 ·