首页 > 解决方案 > 如何使用 datastax 驱动程序将一组元组存储到 cassandra

问题描述

我正在尝试使用 Micronaut 和 Cassandra(当前版本3.11.10)运行我的服务,并将作为一组元组的列存储到 Cassandra 中。

示例代码:

QueryBuilder
    .insertInto(table)
    .value("column", QueryBuilder.literal(items.map { it.toTuple() }.toSet())))

toTuple()方法只是将项目转换为Term对象的扩展方法

当我这样做时,我收到以下错误:

Internal Server Error: Could not inline literal of type java.util.Collections$SingletonSet. This happens because the driver doesn't know how to map it to a CQL type. Try passing a TypeCodec or CodecRegistry to literal().

我已经在多个来源中在线检查过,但找不到一种简单的方法来将一组元组存储到数据库中而不实现我的 custom TypeCodec。我确信我不是第一个遇到这个问题的人,我可能做错了一些事情,但是我找不到任何关于什么是正确方法的文档。

标签: cassandramicronautdatastax-java-driver

解决方案


推荐阅读