我正在尝试使用org.springframework.jdbc.core.simple.SimpleJdbcInsert
类插入这样构建的Cassandra表中:
CREATE TABLE test.profs(id text PRIMARY KEY,
accountid text,
enable boolean,
modifieddate bigint,
name text,
rules set<text>)
当我发送以下请求时:
{
"name": "a",
"rules": [
"s", "22",
"ss",
"sfsf"
],
"enable": true,
"accountId": "sss"
}
(它创建一个id,不用担心-已测试)
但是当我尝试插入时,它引发了以下异常:
PreparedStatementCallback; SQL [INSERT INTO test.profs (accountId, enable, id, modifiedDate, name, rules) VALUES(?, ?, ?, ?, ?, ?)the column index : 7 is greater than the count of bound variable markers in the CQL: 6; nested exception is java.sql.SQLRecoverableException: the column index : 7 is greater than the count of bound variable markers in the CQL: 6
我认为这与rules
列有关,因为当我尝试插入一个元素的数组时,它确实成功了。
编辑:
我尝试使用以下类:
@Data
@AllArgsConstructor
private class CollectionHolder {
private Collection<?> collection;
@Override
public String toString() {
StringBuilder list = new StringBuilder("{");
for (Object obj : collection) {
list.append(obj.toString());
list.append(',');
}
list.delete(list.length()-1, list.length());
list.append('}');
return list.toString();
}
}
它似乎确实成功了,但是现在rules
被插入为null。
有帮助吗?