Bringing together the Apache Cassandra experts from the community and DataStax.

Want to learn? Have a question? Want to share your expertise? You are in the right place!

Not sure where to begin? Getting Started

 

question

mysub99 avatar image
mysub99 asked mysub99 commented

cassandra date data type for java

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

cassandradata modelingjava
4 comments
10 |1000 characters needed characters left characters exceeded

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

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.

2 Likes 2 ·
mysub99 avatar image mysub99 alexandre.dutra ♦ ·

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 ·
Show more comments

0 Answers