我编写了一个自定义保存查询,以便可以在每个项目上添加可配置的TTL。这是我的仓库:
@Repository
public interface MyCassandraRepository extends
TypedIdCassandraRepository<MyCassandraItem, UUID> {
@Query("insert into " + TABLE_NAME + " (" + CQL_UUID + ", " + CQL_PLAN + ") values (?0, ?1) using ttl ?2")
MyCassandraItem customSaveWithTtl(UUID uuid, String plan, Integer ttl);
}
这是我的桌子:
CREATE TABLE IF NOT EXISTS my_users.plans (
user_id uuid,
plan text,
PRIMARY KEY (user_id)
) ;
但是,当我尝试在计划字符串中包含一个句号/句点(例如eyJhbGciOiJIUzUxMiJ9.hsdyu7832uwhjjdsjkdsew2389dhj
)时添加一个条目时,出现以下错误:
org.springframework.cassandra.support.exception.CassandraQuerySyntaxException: line 1:110 mismatched input 'eyJhbGciOiJIUzUxMiJ9' expecting ')' (...plan) values ('c7a8fd65-8ef5-420e-b02e-898fe248bbf3', ''[eyJhbGciOiJIUzUxMiJ9]....); nested exception is com.datastax.driver.core.exceptions.SyntaxError: line 1:110 mismatched input 'eyJhbGciOiJIUzUxMiJ9' expecting ')' (...plan) values ('c7a8fd65-8ef5-420e-b02e-898fe248bbf3', ''[eyJhbGciOiJIUzUxMiJ9]....)
尝试使用CQLSH手动添加它时,也会出现“。”错误:
SyntaxException: line 1:826 no viable alternative at input '.' (... "plan") VALUES (c7a8fd65-8ef5-420e-b02e-898fe248bbf3, [eyJhbGciOiJIUzUxMiJ9].hsdyu7832uwhjjdsjkdse...)
有人能看到我如何添加整个String而不只是停在'。'上吗?
答案 0 :(得分:0)
您可以尝试使用 PreparedStatement
String originalPlan = "eyJhbGciOiJIUzUxMiJ9.hsdyu7832uwhjjdsjkdsew2389dhj";
PreparedStatement preparedStatement = cqlTemplate.getSession().prepare("insert into plans (user_id, plan) values (?, ? )");
Statement insertStatement = preparedStatement.bind(UUIDs.timeBased(), originalPlan );
cqlTemplate.execute(insertStatement);