3

I am trying to insert data with spring-data-cassandra. But I am getting bellow error , when my app is running with SpringBoot(version is 1.5.3)

I add a custom CallHistoriyRespority object implemented CrudResposity in spring-data, and use the save method to insert the data object

I can't find any reason and the problem confused me

Full stack trace :

Caused by: com.datastax.driver.core.exceptions.InvalidQueryException: Expected 8 or 0 byte long for date (13)
at com.datastax.driver.core.Responses$Error.asException(Responses.java:136)
at com.datastax.driver.core.DefaultResultSetFuture.onSet(DefaultResultSetFuture.java:179)
at com.datastax.driver.core.RequestHandler.setFinalResult(RequestHandler.java:177)
at com.datastax.driver.core.RequestHandler.access$2500(RequestHandler.java:46)
at com.datastax.driver.core.RequestHandler$SpeculativeExecution.setFinalResult(RequestHandler.java:799)
at com.datastax.driver.core.RequestHandler$SpeculativeExecution.onSet(RequestHandler.java:633)
at com.datastax.driver.core.Connection$Dispatcher.channelRead0(Connection.java:1070)
at com.datastax.driver.core.Connection$Dispatcher.channelRead0(Connection.java:993)
at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:105)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:356)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:342)
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:335)
at io.netty.handler.timeout.IdleStateHandler.channelRead(IdleStateHandler.java:287)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:356)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:342)
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:335)
at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:102)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:356)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:342)
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:335)
at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:295)
at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:269)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:356)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:342)
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:335)
at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1294)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:356)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:342)
at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:911)
at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:131)
at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:645)
at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:580)
at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:497)
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:459)
at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:131)
at io.netty.util.concurrent.DefaultThreadFactory$DefaultRunnableDecorator.run(DefaultThreadFactory.java:144)
at java.lang.Thread.run(Thread.java:748)

cassandra table description is below :

CREATE TABLE userdevices.callhistorylogs (
userid bigint,
deviceid text,
serialnumber timestamp,
objectid text,
dialtime timestamp,
dialtype int,
duration int,
phone text,
simid int,
targetphone text,
PRIMARY KEY ((userid, deviceid), serialnumber, objectid)

and my java configuration is below :

@Table("callhistorylogs")
public class CallHistoryLogPO{
 @PrimaryKeyColumn(ordinal = 0 ,type = PrimaryKeyType.PARTITIONED)
 private Long userID;

 @PrimaryKeyColumn(ordinal = 1,type = PrimaryKeyType.PARTITIONED)
 private String deviceID;

 @PrimaryKeyColumn(ordinal = 2,type = PrimaryKeyType.CLUSTERED)
 private String serialNumber;

 @PrimaryKeyColumn(ordinal = 3,type = PrimaryKeyType.CLUSTERED)
 private String objectID;

 private Date dialTime;

 private Call.DialType dialType;

 private Integer duration;

 private String phone;

 private Integer simID;

 private String targetPhone;
 .....
}

save method is below :

    CallHistoriesPO callHistories = new CallHistoriesPO();
    callHistories.setUserID(20170627L);
    callHistories.setDeviceID("160129999");
    callHistories.setPhone("17681879236");
    ......
    callHistoryResposity.save(callHistories);
5
  • serialNumber is timestamp which maps to java.util.Date.... while you are using String Commented Jun 27, 2017 at 5:45
  • you are right, I have solved this problem, thanks. Commented Jun 27, 2017 at 6:47
  • if you want you can delete this question... else i can post my comment as answer... so that question will not be unanswered... Thanks Commented Jun 27, 2017 at 10:02
  • @undefined_variable I'd say go ahead and post your comment as an answer. I'll even up-vote you :D Commented Jun 27, 2017 at 14:45
  • @Aaron Done... Thanks... :) Commented Jun 27, 2017 at 17:21

1 Answer 1

4

serialNumber is timestamp in cassandra which maps to java.util.Date, while you are using String for serialNumber.

cql-to-java-type-mapping

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

1 Comment

Note that timestamp will also map to java.time.Instant

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.