[英]Caused by: com.datastax.driver.core.exceptions.InvalidQueryException: Expected 8 or 0 byte long for date (25)
I developing application using Cassandra and SpringBoot.我使用 Cassandra 和 SpringBoot 开发应用程序。 I have written Cassandra query in Java;
我用 Java 编写了 Cassandra 查询;
String userName="testUser";
String lastUpdatedDate="2018-11-29 13:00:43.400";
String tenantName="demo";
Select select = QueryBuilder.select().all()
.from(tenantName,getGenericClass().getSimpleName())
.where(QueryBuilder.eq("user_Name", userName))
.and(QueryBuilder.gt("last_updateddate", lastUpdatedDate))
.allowFiltering()
.limit(100);
return (List<T>) cassandraOperations.select(select, getGenericClass());
last_updateddate is timestamp data type column in Cassandra. last_updateddate 是 Cassandra 中的时间戳数据类型列。 userName and last_updateddate columns are composite key in database and using latest version of Cassandra.
userName 和 last_updateddate 列是数据库中的组合键,使用最新版本的 Cassandra。
while executing getting the following error.执行时出现以下错误。
Caused by: com.datastax.driver.core.exceptions.InvalidQueryException: Expected 8 or 0 byte long for date (25)引起:com.datastax.driver.core.exceptions.InvalidQueryException:日期 (25) 的预期长度为 8 或 0 字节
but但
Issue got resolved after below change.以下更改后问题得到解决。
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
Date date = sdf.parse(lastUpdatedDate);
long timeInSec = date.getTime();
Timestamp ts=new Timestamp(timeInSec);
Date date1=ts;
Select select = QueryBuilder.select().all()
.from(tenantName,getGenericClass().getSimpleName())
.where(QueryBuilder.eq("user_Name", userName))
.and(QueryBuilder.gt("last_updateddate", date1))
.allowFiltering()
.limit(100);
return (List<T>) cassandraOperations.select(select, getGenericClass());
you have to check data type of Cassandra table and use corresponding datatype of java and use it in java code when declaring variable to pass value of column .您必须检查 Cassandra 表的数据类型并使用相应的 java 数据类型,并在声明变量以传递列值时在 java 代码中使用它。
Example : In Cassandra LocalDate then define LocalDate of cassandra.core package in java instead Date or LocalDate of util package.示例:在 Cassandra LocalDate 中,然后在 java 中定义 cassandra.core 包的 LocalDate 而不是 util 包的 Date 或 LocalDate。
check this type mapping between Cassandra vs Java检查Cassandra 与 Java 之间的这种类型映射
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.