我正在尝试使用datastax java驱动程序和绑定语句将单个元素添加到集合类型,即(未在下面测试的语法)
CREATE TABLE claims (
id bigint PRIMARY KEY,
claimed set<text>
);
UPDATE claims SET claimed = claimed + :claimed WHERE id = :id
当我运行BoundStatement
时,我收到Codec not found for requested operation: [set<varchar> <-> java.lang.String]
我真的要编写一个编解码器吗?
答案 0 :(得分:2)
将CQL追加(+
)到set
需要set
。因此,驱动程序需要Set<String>
而不是String
。要解决这个问题,你需要将String值包装在一个集合中,即:
PreparedStatement prepared = session.prepare("UPDATE claims SET claimed = claimed + :claimed WHERE id = :id");
session.execute(prepared.bind(Collections.singleton("value"), id));