2015-03-31 45 views
0

我有一個kundera模型實體,它具有字符串作爲Id。它是這樣定義的。Kundera和Cassandra單元問題 - 字符串作爲主鍵

@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); 
+0

*搜索幫助詳盡 – 2015-03-31 12:29:18

+0

在您的cassandra集羣上打開一個cqlsh會話,並編輯您的答案以包含'desc table process_requests'的輸出。 – Aaron 2015-03-31 13:37:13

+0

我在我的問題中添加了表格說明。 – 2015-04-03 09:51:23

回答

1

如果使用CQL2創建您的架構,使用任何名稱主鍵列與名'key'創建。

這是由昆德拉處理,如果您使用createQueryfindById。由於您正在使用native query更改where id = ...where key = ...

PS:與昆德拉合作時,首選CQL3。您可以參考this瞭解更多關於CQL3的信息。

+0

嗨,我只使用cql3。查詢在應用程序正常運行時工作正常,但在與cassandra單元一起運行時沒有問題。 – 2015-04-03 09:52:10

+0

它使用'key'關鍵字後工作,但是當我正常運行應用程序時它不工作,它只與嵌入式cassandra一起工作。任何方式來解決它? – 2015-04-07 12:41:35

+0

您確定您不使用CQL2-CQL3可互換地創建和檢索數據嗎? – 2015-04-07 12:44:36