弹簧数据卡桑德拉自定义插入查询在字符串中的'.'失败



我已经写了一个自定义保存查询,以便我可以在每个项目上添加可配置的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 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);

最新更新