When using a composite primary key for a Cassandra-mapped entity, it should be possible to define which column(s) should form the partition key and the order of columns in the partition and clustering key. Maybe something like this:
@Entity
class OrderLine {
@EmbeddedId
public OrderLinePk pk;
...
}
@Embeddable
class OrderLinePk {
@PartitionKey
public long orderNo;
public short serialNo;
}
The primary key created in Cassandra would be (orderno, serialno) (the first column given is the partition key). Or with a compound partition key:
@Embeddable
class OrderLinePk {
@PartitionKey(order=1)
public String customer;
@PartitionKey(order=2)
public long orderNo;
public short serialNo;
}
The primary key created in Cassandra would be ((customerno, orderno), serialno) (the columns in the first brackets form the partition key). Similarly for @ClusteringKey(order=123 if there is more than one clustering key column. Some useful resources:
|