2

我花了一整天的时间尝试将数据插入到一个简单的 cassandra 数据库中,用于存储用户名、密码、电子邮件和电话。我所做的所有研究都会让我回到http://hector-client.github.com/hector/build/html/content/getting_started.html#update。我已经按照这些示例进行了操作,但是当我尝试执行我的代码时:

        ConfigurableConsistencyLevel ccl = new ConfigurableConsistencyLevel();
    Map<String, HConsistencyLevel> clm = new HashMap<String, HConsistencyLevel>();

    clm.put("customers", HConsistencyLevel.ONE);
    ccl.setReadCfConsistencyLevels(clm);
    ccl.setWriteCfConsistencyLevels(clm);
    Cluster cluster = HFactory.getOrCreateCluster("test-cluster", "localhost:9160");     

    Keyspace ksp = HFactory.createKeyspace("qualebs", cluster);
    ksp.setConsistencyLevelPolicy(ccl);

    ColumnFamilyTemplate<String, String> template = new ThriftColumnFamilyTemplate<String, String>(ksp, "customers", StringSerializer.get(), StringSerializer.get());

    ColumnFamilyUpdater<String, String> updater = template.createUpdater("KeyIsUsername");
    updater.setString("name", "the name");
    updater.setString("email", "email@email.com");
    template.update(updater);

尝试运行我的应用程序时出现以下异常:

Caused by: InvalidRequestException(why:Not enough bytes to read value of component 0)
at org.apache.cassandra.thrift.Cassandra$batch_mutate_result.read(Cassandra.java:20833)
at org.apache.thrift.TServiceClient.receiveBase(TServiceClient.java:78)
at org.apache.cassandra.thrift.Cassandra$Client.recv_batch_mutate(Cassandra.java:964)
at org.apache.cassandra.thrift.Cassandra$Client.batch_mutate(Cassandra.java:950)
at me.prettyprint.cassandra.model.MutatorImpl$3.execute(MutatorImpl.java:246)
at me.prettyprint.cassandra.model.MutatorImpl$3.execute(MutatorImpl.java:243)
at me.prettyprint.cassandra.service.Operation.executeAndSetResult(Operation.java:104)
at me.prettyprint.cassandra.connection.HConnectionManager.operateWithFailover(HConnectionManager.java:258)
... 57 more

我需要帮助来了解此错误的原因。

我从 cqlsh 终端创建的架构看起来像

 CREATE TABLE customers(username text PRIMARY KEY, name text, email text);
4

1 回答 1

1

另一种选择可能是尝试 playOrm,它会为您正确转换并为您创建 CF,因此您不必担心创建错误;)。只是一种选择。

通过PlayOrm主页或GitHub获取框架

于 2013-03-08T13:39:11.500 回答