无法解析writeoptions的属性[retrypolicy]的数据类型

f1tvaqid  于 2021-06-10  发布在  Cassandra
关注(0)|答案(1)|浏览(378)

SpringBootVersion2.1.9.发布并使用SpringBootStarter数据的依赖项cassandra
对于以下代码段

WriteOptions ttlOption = WriteOptions.builder().ttl(5).build();
CassandraBatchOperations batchOperations = cassandraTemplate.batchOps();
batchOperations.insert(myEntityClass, ttlOption);

我们当前得到以下异常

Caused by: org.springframework.data.mapping.MappingException: Cannot resolve DataType for property [retryPolicy] in entity [org.springframework.data.cassandra.core.cql.WriteOptions]; Consider adding @CassandraType.
at org.springframework.data.cassandra.core.mapping.CassandraMappingContext.getDataTypeWithUserTypeFactory(CassandraMappingContext.java:612)
at org.springframework.data.cassandra.core.mapping.CassandraMappingContext.getDataType(CassandraMappingContext.java:556)
at org.springframework.data.cassandra.core.convert.MappingCassandraConverter.getPropertyTargetType(MappingCassandraConverter.java:710)
at org.springframework.data.cassandra.core.convert.MappingCassandraConverter.lambda$getTargetType$3(MappingCassandraConverter.java:700)
at java.base/java.util.Optional.orElseGet(Optional.java:369)
at org.springframework.data.cassandra.core.convert.MappingCassandraConverter.getTargetType(MappingCassandraConverter.java:688)
at org.springframework.data.cassandra.core.convert.MappingCassandraConverter.getWriteValue(MappingCassandraConverter.java:731)
at org.springframework.data.cassandra.core.convert.MappingCassandraConverter.writeInsertFromWrapper(MappingCassandraConverter.java:420)
at org.springframework.data.cassandra.core.convert.MappingCassandraConverter.write(MappingCassandraConverter.java:363)
at org.springframework.data.cassandra.core.convert.MappingCassandraConverter.write(MappingCassandraConverter.java:347)
at org.springframework.data.cassandra.core.QueryUtils.createInsertQuery(QueryUtils.java:107)
at org.springframework.data.cassandra.core.CassandraBatchTemplate.insert(CassandraBatchTemplate.java:121)
at org.springframework.data.cassandra.core.CassandraBatchTemplate.insert(CassandraBatchTemplate.java:100)
at org.springframework.data.cassandra.core.CassandraBatchTemplate.insert(CassandraBatchTemplate.java:92)

我错过了什么?

ippsafx7

ippsafx71#

找到了答案。
原来参数列表是

CassandraBatchOperations insert(Object... var1);
CassandraBatchOperations insert(Iterable<?> var1);
CassandraBatchOperations insert(Iterable<?> var1, WriteOptions var2);

因此,我需要将参数作为iterable提供,以便能够将writeoptions作为第二个参数。
例如

batchOperations.insert(List.of(myEntityClass), ttlOption);

相关问题