0

I am using below Datastax versions with Java 8:

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

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

My table has a Date column as below:

cass_table (                                                    
    data_source_id int,                                                                                                                                                                   
    company_id text,                                                              
    create_date date)  

         

When I trying to save the data into C* table as below:

final IndustryCompany four = new IndustryCompany(1,1236, ProdUtils.today());
 industryCompanyRepository.save(one);


public static Date today() {
        return java.sql.Date.valueOf(new SimpleDateFormat(ProducerConstants.DATABASE_DATE_FORMAT).format(Calendar.getInstance().getTime()));
    }

Getting error:

Caused by: com.datastax.driver.core.exceptions.CodecNotFoundException: Codec not found for requested operation: [date <-> java.sql.Date]
    at com.datastax.driver.core.exceptions.CodecNotFoundException.copy(CodecNotFoundException.java:57) ~[cassandra-driver-core-3.7.2.jar:na]

What am I doing wrong here?

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

4 Comments

thank you ... When I use version 4.0.0 instead of current version 3.7.2 to run github.com/lankydan/datastax-java-driver ... there are lot of errors... is there any samples/examples to use version 4.0.0 ???
4.x is major rewrite of the Java driver, and it's not binary compatible. There is a separate part of manual regarding porting: docs.datastax.com/en/developer/java-driver/4.1/upgrade_guide And examples are in repository: github.com/datastax/java-driver/tree/4.x/examples
thank you , what do you mean by "not binary compatible" ??
That you can’t simply take your compiled code and use with new driver version, as there are API changes
-1

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);
}

1 Comment

you can look into my answer stackoverflow.com/a/45815737/2320144

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.