将spring数据cassandra升级到最新的2.0.7.RELEASE后,获取RetryPolicy错误的未知类型

时间:2018-06-13 20:40:21

标签: spring-data-cassandra

我更新了这些代码行以支持spring-data-cassandra-2.0.7.RELEASE:

CassandraOperations cOps = new CassandraTemplate(session);  

自:

Insert insertStatement = (Insert)statement;
CqlTemplate.addWriteOptions(insertStatement, queryWriteOptions);
cOps.execute(insertStatement);

要:

Insert insertStatement = (Insert)statement;
insertStatement = QueryOptionsUtil.addWriteOptions(insertStatement, 
queryWriteOptions);
cOps.insert(insertStatement);

以上更改将丢失以下错误:

Caused by: org.springframework.dao.InvalidDataAccessApiUsageException: Unknown type [interface com.datastax.driver.core.policies.RetryPolicy] for property [retryPolicy] in entity [com.datastax.driver.core.querybuilder.Insert]; only primitive types and Collections or Maps of primitive types are allowed
    at org.springframework.data.cassandra.core.mapping.BasicCassandraPersistentProperty.getDataType(BasicCassandraPersistentProperty.java:170)
    at org.springframework.data.cassandra.core.mapping.CassandraMappingContext.lambda$null$10(CassandraMappingContext.java:552)
    at java.util.Optional.orElseGet(Optional.java:267)
    at org.springframework.data.cassandra.core.mapping.CassandraMappingContext.lambda$getDataTypeWithUserTypeFactory$11(CassandraMappingContext.java:542)
    at java.util.Optional.orElseGet(Optional.java:267)
    at org.springframework.data.cassandra.core.mapping.CassandraMappingContext.getDataTypeWithUserTypeFactory(CassandraMappingContext.java:527)
    at org.springframework.data.cassandra.core.mapping.CassandraMappingContext.getDataType(CassandraMappingContext.java:486)
    at org.springframework.data.cassandra.core.convert.MappingCassandraConverter.getPropertyTargetType(MappingCassandraConverter.java:689)
    at org.springframework.data.cassandra.core.convert.MappingCassandraConverter.lambda$getTargetType$0(MappingCassandraConverter.java:682)
    at java.util.Optional.orElseGet(Optional.java:267)
    at org.springframework.data.cassandra.core.convert.MappingCassandraConverter.getTargetType(MappingCassandraConverter.java:670)
    at org.springframework.data.cassandra.core.convert.MappingCassandraConverter.getWriteValue(MappingCassandraConverter.java:711)
    at org.springframework.data.cassandra.core.convert.MappingCassandraConverter.writeInsertFromWrapper(MappingCassandraConverter.java:403)
    at org.springframework.data.cassandra.core.convert.MappingCassandraConverter.writeInsertFromObject(MappingCassandraConverter.java:360)
    at org.springframework.data.cassandra.core.convert.MappingCassandraConverter.write(MappingCassandraConverter.java:345)
    at org.springframework.data.cassandra.core.convert.MappingCassandraConverter.write(MappingCassandraConverter.java:320)
    at org.springframework.data.cassandra.core.QueryUtils.createInsertQuery(QueryUtils.java:78)
    at org.springframework.data.cassandra.core.CassandraTemplate.insert(CassandraTemplate.java:442)
    at org.springframework.data.cassandra.core.CassandraTemplate.insert(CassandraTemplate.java:430)

作为输入传递的查询的类型为com.datastax.driver.core.querybuilder.Insert,其中包含:

INSERT INTO person (name,id,age) VALUES ('name01','123',23) USING TIMESTAMP 1528922717378000 AND TTL 60;

传递包含RetryPolicy和一致性级别的查询选项。 根据上面提到的文档,更改无效。任何人都可以让我知道这里有什么问题吗?

我使用Spring 2.0.7.RELEASE和Cassandra驱动程序3.5.0

2 个答案:

答案 0 :(得分:1)

我能够使用以下更改来处理它:

cOps.getCqlOperations().execute(insertStatement);

如果应用了一致性级别,我如何检查它?

答案 1 :(得分:0)

对我来说,这可行:

documentSnapshots