gpt4 book ai didi

java - 如何使用 Hector 在 Cassandra 中保留新的客户行?

转载 作者:行者123 更新时间:2023-11-30 11:35:09 25 4
gpt4 key购买 nike

我花了一整天的时间尝试将数据插入到一个简单的 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);

最佳答案

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

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

关于java - 如何使用 Hector 在 Cassandra 中保留新的客户行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15268330/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com