【发布时间】:2017-01-17 07:55:22
【问题描述】:
我正在使用 datastax cassandra 3.1.0。我在 cassandra 中创建了下表并插入了一条记录。
CREATE TABLE collect_things ( k int PRIMARY KEY, v frozen <tuple <int, text, double>> );
INSERT INTO collect_things (k, v) VALUES(0, (3, 'bar', 2.1));
select * from collect_things ;
k | v
---+-----------------
0 | (3, 'bar', 2.1)
当我尝试使用带有以下代码的 Cassandra Mapper 在 Java 中获取上述行时:
this.cluster = Cluster.builder().addContactPoint(node).withPort(port).build();
session = cluster.connect();
MappingManager manager = new MappingManager(session);
Mapper<CollectThings> mapper = manager.mapper(CollectThings.class);
Integer k = 0;
mapper.get(k);
我收到以下异常:
Exception in thread "main" com.datastax.driver.core.exceptions.CodecNotFoundException: Codec not found for requested operation: [frozen<tuple<int, varchar, double>> <-> com.datastax.driver.core.TupleType]
at com.datastax.driver.core.exceptions.CodecNotFoundException.copy(CodecNotFoundException.java:56)
at com.datastax.driver.core.exceptions.CodecNotFoundException.copy(CodecNotFoundException.java:25)
at com.datastax.driver.mapping.DriverThrowables.propagateCause(DriverThrowables.java:41)
at com.datastax.driver.mapping.Mapper.get(Mapper.java:432)
我为上表准备了以下 java bean。 CollectThings.java
import com.datastax.driver.core.TupleType;
import com.datastax.driver.mapping.annotations.Frozen;
import com.datastax.driver.mapping.annotations.PartitionKey;
import com.datastax.driver.mapping.annotations.Table;
@Table(keyspace = "user_info", name = "collect_things")
public class CollectThings {
private Integer k;
private TupleType v;
public CollectThings() {
}
@PartitionKey
public Integer getK() {
return k;
}
public void setK(Integer k) {
this.k = k;
}
@Frozen
public TupleType getV() {
return v;
}
public void setV(TupleType v) {
this.v = v;
}
}
有人可以在这里告诉如何处理元组类型吗?开箱即用的映射器不支持 cql 元组类型吗?
【问题讨论】:
标签: datastax-java-driver cassandra-3.0