Kundera和Cassandra单位问题 - 字符串作为主键

时间:2015-03-31 12:28:40

标签: cassandra kundera

我有一个kundera模型实体,它有String作为Id。它定义如下。

@Id
private String id;

我有一个方法,我正在执行这样的本机查询。

/**
     * @param requestId
     * @return
     */
    public static ProcessRequest getRequest(Serializable requestId) {
        List<ProcessRequest> requests = execute("SELECT * from
            process_requests where id = '" + requestId + "';");
        return requests.isEmpty() ? null : requests.get(0);
    }

运行像这样的单元测试时,我收到以下异常。

17:50:38.716 [main] ERROR c.i.c.cassandra.CassandraClientBase - Error during executing query SELECT * from process_requests where id = '5b4468e0-6146-4fbc-81cf-571371834446';, Caused by: {} .
com.impetus.kundera.KunderaException: InvalidRequestException(why:Undefined name id in where clause ('id EQ '5b4468e0-6146-4fbc-81cf-571371834446''))
    at com.impetus.client.cassandra.CassandraClientBase.execute(CassandraClientBase.java:2101) [kundera-cassandra-2.14.jar:na]
    at com.impetus.client.cassandra.CassandraClientBase.executeCQLQuery(CassandraClientBase.java:1708) [kundera-cassandra-2.14.jar:na]
    at com.impetus.client.cassandra.CassandraClientBase$CQLClient.executeQuery(CassandraClientBase.java:1851) [kundera-cassandra-2.14.jar:na]
    at com.impetus.client.cassandra.CassandraClientBase.executeSelectQuery(CassandraClientBase.java:761) [kundera-cassandra-2.14.jar:na]
    at com.impetus.client.cassandra.thrift.ThriftClient.executeQuery(ThriftClient.java:860) [kundera-cassandra-2.14.jar:na]
    at com.impetus.client.cassandra.query.CassQuery.populateEntities(CassQuery.java:143) [kundera-cassandra-2.14.jar:na]
    at com.impetus.kundera.query.QueryImpl.fetch(QueryImpl.java:1013) [kundera-core-2.14.jar:na]
    at com.impetus.kundera.query.QueryImpl.getResultList(QueryImpl.java:164) [kundera-core-2.14.jar:na]

即使有一个由id定义的列,它也会给出这个例外情况,而且我有一个彻底的帮助,无法解决它。你能帮忙解决这个问题吗?

更新:

CREATE TABLE docyard.process_requests (
id text PRIMARY KEY,
content_type text,
created_at timestamp,
document_id text,
lock bigint,
lock_expiration timestamp,
namespace text,
process_input text,
process_output text,
processed text,
updated_at timestamp,
version_id text
) WITH bloom_filter_fp_chance = 0.01
AND caching = '{"keys":"ALL", "rows_per_partition":"NONE"}'
AND comment = ''
AND compaction = {'min_threshold': '4', 'class':           'org.apache.cassandra.db.compaction.SizeTieredCompactionStrategy',       'max_threshold': '32'}
AND compression = {'sstable_compression': 'org.apache.cassandra.io.compress.LZ4Compressor'}
AND dclocal_read_repair_chance = 0.1
AND default_time_to_live = 0
AND gc_grace_seconds = 864000
AND max_index_interval = 2048
AND memtable_flush_period_in_ms = 0
AND min_index_interval = 128
AND read_repair_chance = 0.0
AND speculative_retry = '99.0PERCENTILE';
CREATE INDEX process_requests_lock_idx ON docyard.process_requests  (lock);
CREATE INDEX process_requests_processed_idx ON docyard.process_requests (processed);

1 个答案:

答案 0 :(得分:1)

如果您使用CQL2创建架构,则会使用名称'key'创建具有任何名称的主键列。

如果您使用createQueryfindById,则由Kundera处理。由于您使用native querywhere id = ...更改为where key = ...

PS:与昆德拉合作时首选CQL3。有关CQL3的更多信息,请参阅this