Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

java

cassandra

In Cassandra a column type is set to Date and in Model class type of field is set to java.util.Date with getters and setters. During com.datastax.driver.mapping.Mapper.save I get the following exception:

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

Caused by: com.datastax.driver.core.exceptions.CodecNotFoundException: Codec not found for requested operation: [date <-> java.util.Date]
at com.datastax.driver.core.exceptions.CodecNotFoundException.copy(CodecNotFoundException.java:56)
at com.datastax.driver.core.exceptions.CodecNotFoundException.copy(CodecNotFoundException.java:25)
at com.datastax.driver.mapping.DriverThrowables.propagateCause(DriverThrowables.java:41)
at com.datastax.driver.mapping.Mapper.save(Mapper.java:272)

Found the following during Google search:

DATE      <-> com.datastax.driver.core.LocalDate : use getDate()
like image 455
Vijay Nandwana Avatar asked Jan 05 '17 08:01

Vijay Nandwana


2 Answers

You must convert java.util.Date to com.datastax.driver.core.LocalDate

Example:

 LocalDate localDate = LocalDate.fromMillisSinceEpoch(date.getTime());
like image 179
itstata Avatar answered Oct 13 '22 22:10

itstata


I was facing the same issue with using timestamp

reactor.core.Exceptions$ErrorCallbackNotImplemented: com.datastax.oss.driver.api.core.type.codec.CodecNotFoundException: Codec not found for requested operation: [TIMESTAMP <-> java.util.Date]
Caused by: com.datastax.oss.driver.api.core.type.codec.CodecNotFoundException: Codec not found for requested operation: [TIMESTAMP <-> java.util.Date]
    at com.datastax.oss.driver.internal.core.type.codec.registry.CachingCodecRegistry.createCodec(CachingCodecRegistry.java:609) ~[java-driver-core-4.9.0.jar:na]
    at com.datastax.oss.driver.internal.core.type.codec.registry.DefaultCodecRegistry$1.load(DefaultCodecRegistry.java:95) ~[java-driver-core-4.9.0.jar:na]
    at com.datastax.oss.driver.internal.core.type.codec.registry.DefaultCodecRegistry$1.load(DefaultCodecRegistry.java:92) ~[java-driver-core-4.9.0.jar:na]

Starting with driver 4.0, the CQL type timestamp is not mapped to java.util.Date anymore, but to java.time.Instant. Using Instant worked for me.

like image 42
rajat behl Avatar answered Oct 13 '22 20:10

rajat behl