我花了整整一天的时间试图将数据插入简单的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 protected]");
    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);

最佳答案

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

通过PlayOrm主页或通过GitHub获取框架

09-05 06:31