在Java连接Cassandra的情况下, 当使用组合主键时, 默认第一个是Partition Key, 后续的均为Clustering Key.
如果有多个Clustering Key, 在Java中需指定Clustering Key的Order顺序, 否则将出现 "The clustering keys ordering is wrong for @EmbeddedId" 错误。
代码示例:
`@Entity(table = "table_name")
public class DemoDO {@EmbeddedIdprivate CompoundKey id;public static class CompoundKey { @PartitionKey @Column(name = "filed_one") public String fieldOne; @ClusteringColumn(1) @Column(name = "field_two") private String fieldTwo; @ClusteringColumn(2) @Column(name = "field_three") private Date fieldThree; public CompoundKey() { } public CompoundKey(String fieldOne, String fieldTwo, Date fieldThree) { this.fieldOne= fieldOne; this.fieldTwo= fieldTwo; this.fieldThree= fieldThree; } ...}@Column(name = "field_four")private String fieldFour;
...
} `