Cassandra:插入timeuuid错误

Cassandra:插入timeuuid错误,cassandra,cql,datastax-java-driver,Cassandra,Cql,Datastax Java Driver,我有下表 create table test( userId varchar, notifId timeuuid, notification varchar, time bigint,read boolean, primary key(userId, notifId)) with clustering order by (notifId desc); 我正在运行以下查询: PreparedStatemen

我有下表

create table test(
         userId varchar,
         notifId timeuuid,
         notification varchar,
         time bigint,read boolean,
         primary key(userId, notifId)) with clustering order by (notifId desc);
我正在运行以下查询:

PreparedStatement   pstmt  = session.prepare("INSERT INTO notifications(userId, notifId, notification, time, read) VALUES(?, now(), ?, ?, ?)");

BoundStatement      boundStatement  = new BoundStatement(pstmt);
        session.execute(boundStatement.bind("123", "hello", new Date().getTime(), false));
我遇到以下错误:

Exception in thread "main" com.datastax.driver.core.exceptions.InvalidQueryException: Type error: cannot assign result of function now (type timeuuid) to notifid (type 'org.apache.cassandra.db.marshal.ReversedType(org.apache.cassandra.db.marshal.TimeUUIDType)')
    at com.datastax.driver.core.exceptions.InvalidQueryException.copy(InvalidQueryException.java:35)
    at com.datastax.driver.core.ResultSetFuture.extractCause(ResultSetFuture.java:277)
    at com.datastax.driver.core.Session.toPreparedStatement(Session.java:281)
    at com.datastax.driver.core.Session.prepare(Session.java:172)
    at com.example.cassandra.SimpleClient.loadData(SimpleClient.java:130)
    at com.example.cassandra.SimpleClient.main(SimpleClient.java:214)
Caused by: com.datastax.driver.core.exceptions.InvalidQueryException: Type error: cannot assign result of function now (type timeuuid) to notifid (type 'org.apache.cassandra.db.marshal.ReversedType(org.apache.cassandra.db.marshal.TimeUUIDType)')
    at com.datastax.driver.core.ResultSetFuture.convertException(ResultSetFuture.java:307)

我使用的是cassandra 1.2.2。

您应该插入通过datastax驱动程序生成的timeuuid。在您的情况下,由于您使用的是版本1 timeuuid,因此必须使用

UUIDs.timeBased()

您可以在以下参考资料中找到上述内容


它看起来像一个bug(与类似或相同),您使用的是非常旧的Cassandra版本。我建议您升级到最新的1.2.x版本,重新测试您的场景并提交问题,如果问题仍然存在

并且此类的路径是导入com.datastax.driver.core.utils.UUIDs