【发布时间】: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)
【问题讨论】:
-
嗨,我还在为此苦苦挣扎,谁能帮忙。