我正在尝试将Datastax的UDT映射器用于包含UDT列表的表。尝试实例化UDTmapper时,驱动程序抛出异常。它似乎无法映射代表我的UDT的类的实例列表。
使用以下语句创建用户定义的类型和表:
CREATE TYPE IF NOT EXISTS keyspace.value (
id uuid,
values list<text>
);
CREATE TYPE IF NOT EXISTS keyspace.epoch (
name text,
description text,
start_time timestamp,
duration int,
values list<frozen<value>>
);
CREATE TABLE IF NOT EXISTS keyspace.service_level_agreements (
id uuid,
name text,
description text,
epochs list<frozen<epoch>>,
chargeback_info uuid,
PRIMARY KEY (id)
);
课程是:
public class Value {
@Field(name = "id")
private UUID sloId;
@Field(name = "values")
private List<String> values;
}
public class Epoch {
@Field(name = "name")
private String name;
@Field(name = "description")
private String description;
@Field(name = "start_time")
private Date startTime;
@Field(name = "duration")
private long duration;
@Field(name = "values")
private List<Value> values;
}
@UDT (keyspace = "keyspace", name = "service_level_agreements")
public class ServiceLevelAgreement e {
@Field(name = "id")
private UUID id;
@Field(name = "name")
private String name;
@Field(name = "description")
private String description;
@Field(name = "epochs")
private List<Epoch> epochs;
@Field(name = "chargeback_info")
private UUID charegebackInfo;
}
当我尝试实例化UDT映射器时,我得到一个例外:
Cannot map unknown class com.me.Epoch for field private java.util.List com.me.ServiceLevelAgreement.epochs
似乎UDT映射器不能为Epoch类提供资金,尽管它位于类路径上。我也尝试在ServiceLevelAgreement中移动Epoch类,但它没有帮助。任何想法我做错了什么?
答案 0 :(得分:1)
这个问题是由于我误解了应该用@UDT注释标记哪个类引起的。我把它放在表注释中,但它应该在描述我的UDT的类中。在我修改了注释后,一切都开始工作了。