我正在为 Spring 天为Cassandra设置一个DAO .
现在我有一个关于在对象中多次使用复合类的问题 .
我有这个课程设置:
@Table(value = "settings")
public class Setting {
@PrimaryKey
private User owner;
@Column("key")
private String key;
@Column("value")
private String value;
@Column("updated_by")
private User updatedBy;
}
和 class 用户:
@PrimaryKeyClass
public class User implements Serializable{
@PrimaryKeyColumn(name = "userId", ordinal = 0, type = PrimaryKeyType.PARTITIONED)
private String id;
@PrimaryKeyColumn(name = "userIdType", ordinal = 1, type = PrimaryKeyType.PARTITIONED)
private String idType;
}
所以我两次使用类User . 一旦作为主键“所有者”,一次作为“updatedBy” .
在CassandraOperations类中使用它时,它可以作为主键使用,但不能再作为另一列 .
它抱怨已经使用了列名 userId
. 说得通 . 那么我怎样才能做到这一点呢?
我可以使用UserDefined类型吗?
CREATE TYPE test_keyspace.user (
id text,
id_type text
);
但是我如何从java Annotations中做到这一点?
或者,我怎样才能重用同一个类呢?考虑到Cassandra中相对简单的数据结构,我可以将User类扁平化为单个字符串,如 idType.id
.
谢谢你的帮助!
1 回答
好的,发现它是here,由denzal回答 .
我的课程现在看起来像:
和用户类:
很好地工作 .