字典java cassandra对象映射注释
您能否提供一个使用datastax api注释映射集合以使用Map的示例
class pojo {
@PartitionKey(value = 0)
@Column(name = "user_id")
String userId;
@Column(name = "attributes")
// How to map it
Map<String, String> attributes;
}
错误日志:
2015-08-03 16:33:34,568 INFO com.jpma.jpmc.slot.persistance.DAOFactory main - Cassandra Cluster Details: ConnectionCfg [userName=test, password=test, port=9042, seeds=[Ljava.lang.String;@1a85bd75, keySpace=test]
java.lang.Class
2015-08-03 16:33:34,646 DEBUG com.datastax.driver.mapping.EntityMapper main - Preparing query INSERT INTO "test"."user_event_date"("user_id","entry_date","entry_time","app","attributes","user_ip","user_authschemes") VALUES (?,?,?,?,?,?,?);
com.datastax.driver.core.exceptions.InvalidQueryException: Unknown identifier attributes
# 1 楼答案
根据您看到的错误消息,我猜表定义中没有定义
attributes
。你介意用这个来编辑你的帖子吗但是当我像这样构建CQL表时(注意
itemid
和version
的复合分区键):。。。插入此行:
。。。我的POJO是这样建造的:
。。。在我的数据访问对象(dao)上使用此构造函数和
getProd
方法:。。。然后这个
main
类成功地查询了我的表并映射了我的Map
:。。。并产生以下输出:
注意:对上述示例进行编辑以支持复合分区键