【问题标题】:Unable to insert values in cassandra db using Hector无法使用 Hector 在 cassandra db 中插入值
【发布时间】:2012-08-04 02:53:51
【问题描述】:

我正在使用 hector 在 cassandra DB 中插入值。我是 Eclipse helios IDE 和 Cassandra 1.1.2 版,在我的类路径中导入了以下 jar。

  • apache-cassandra-1.1.2.jar
  • hector-core-0.7.0.29.jar
  • libthrift-0.8.0.jar
  • slf4j-api-1.6.6.jar

我没有发现这里有什么问题,可能是兼容性问题,也可能是代码有问题。

我尝试使用不同版本的罐子,但没有运气。 以下是代码sn-p。

请帮忙。

int count = 0;
StringSerializer ss = StringSerializer.get();
String cf = "TESTING";
CassandraHostConfigurator conf = new CassandraHostConfigurator("10.100.10.177:8160");
System.out.println("host configured..");

conf.setCassandraThriftSocketTimeout(40000);
conf.setExhaustedPolicy(ExhaustedPolicy.WHEN_EXHAUSTED_BLOCK);
conf.setRetryDownedHostsDelayInSeconds(5);
conf.setRetryDownedHostsQueueSize(128);
conf.setRetryDownedHosts(true);
conf.setLoadBalancingPolicy(new LeastActiveBalancingPolicy());
String key = Long.toString(System.currentTimeMillis());
Cluster cluster = HFactory.getOrCreateCluster("Test Cluster", conf);
Keyspace keyspace = HFactory.createKeyspace("Testing", cluster);
Mutator<String> mutator = HFactory.createMutator(keyspace, StringSerializer.get());

while (!"q".equals(new Scanner(System.in).next().toString())) {
    try {
        mutator.insert(key, cf, HFactory.createColumn("column_" + count, "v_" + count, ss, ss));
        mutator.execute();
        count++;
    } catch (Exception e) {
        e.printStackTrace();
    }
}

这是我在没有循环的情况下插入单个值时遇到的异常。

Exception in thread "main" java.lang.NoSuchMethodError: org.apache.cassandra.thrift.Column.<init>(Ljava/nio/ByteBuffer;Ljava/nio/ByteBuffer;J)V
at me.prettyprint.cassandra.model.HColumnImpl.<init>(HColumnImpl.java:36)
at me.prettyprint.hector.api.factory.HFactory.createColumn(HFactory.java:477)
at me.prettyprint.hector.api.factory.HFactory.createStringColumn(HFactory.java:488)
at ExampleDaoV2.main(ExampleDaoV2.java:66)

【问题讨论】:

  • 嗨,我还在为此苦苦挣扎,谁能帮忙。

标签: java cassandra hector


【解决方案1】:

尝试使用除 libthrift 之外的其他 thrift jar 文件。 让我知道这是否有效。

【讨论】:

  • 谁能推荐我可以使用的稳定罐子(hector、thrift 和 cassandra)。仍然是一些不兼容的问题。
猜你喜欢
  • 2012-03-04
  • 2013-08-27
  • 1970-01-01
  • 2012-07-05
  • 2012-02-28
  • 2013-02-06
  • 2012-08-07
  • 2018-09-20
  • 1970-01-01
相关资源
最近更新 更多