引起:com.datastax.driver.core.exceptions.InvalidQueryException:预计日期为 8 或 0 字节长 (13)
Posted
技术标签:
【中文标题】引起:com.datastax.driver.core.exceptions.InvalidQueryException:预计日期为 8 或 0 字节长 (13)【英文标题】:Caused by: com.datastax.driver.core.exceptions.InvalidQueryException: Expected 8 or 0 byte long for date (13) 【发布时间】:2017-11-30 01:04:32 【问题描述】:我正在尝试使用 spring-data-cassandra 插入数据。但是当我的应用程序使用 SpringBoot(版本为 1.5.3)运行时,我收到以下错误
我在spring-data中添加了一个自定义的CallHistoriyRespority对象实现了CrudResposity,并使用save方法插入数据对象
我找不到任何原因,这个问题让我很困惑
完整的堆栈跟踪:
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 表描述如下:
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)
我的java配置如下:
@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;
.....
保存方法如下:
CallHistoriesPO callHistories = new CallHistoriesPO();
callHistories.setUserID(20170627L);
callHistories.setDeviceID("160129999");
callHistories.setPhone("17681879236");
......
callHistoryResposity.save(callHistories);
【问题讨论】:
serialNumber
是映射到java.util.Date
....的时间戳,而您正在使用String
你说得对,我已经解决了这个问题,谢谢。
如果你愿意,你可以删除这个问题...否则我可以发表我的评论作为答案...这样这个问题就不会没有答案...谢谢
@undefined_variable 我想说继续发表您的评论作为答案。我什至会投票给你:D
@Aaron 完成...谢谢... :)
【参考方案1】:
serialNumber
是 cassandra 中的时间戳,它映射到 java.util.Date
,而您将 String
用于 serialNumber
。
cql-to-java-type-mapping
【讨论】:
请注意,timestamp
也将映射到 java.time.Instant
以上是关于引起:com.datastax.driver.core.exceptions.InvalidQueryException:预计日期为 8 或 0 字节长 (13)的主要内容,如果未能解决你的问题,请参考以下文章
csharp 可能会引起问题的类的继承问题,父类后来增加的方法可能会引起子类的函数重载错误