Kundera persistence entity definition with partition key and cluster key

℡╲_俬逩灬. 提交于 2019-12-11 04:26:56

问题


I am trying to use Kundera for connecting to Cassandra. In my case I have an Entity X with Partition Key {A,B} and cluster key {C}.

We have multiple values of C for each A and B combination(primary key).

So in such case how should be define the entity?

@Embeddable
public class PrimayKey implements Serializable{

 @Column(name = "A")
     private String a;

     @Column(name = "B")
     private String b;
}




@Entity
@Table(name = "X")
public class X{


    @EmbeddedId
    private PrimayKey key;

    @Column(name = "C")
    private String c;

   @Column(name = "D")
    private String d;
}

Here if I go for a find by Primary Key its not working as we have multiple values of C and D for each A and B combination. In such case how should we define entity?


回答1:


You can create an embeddable for partition key and then use it as a field in primary key. Kundera will automatically read the entities and consider the fields other than partition keys as clustering keys.

Cassandra equivalent Primary key : ((A, B), C)

Entity :

@Embeddable
public class PartitionKey {

 @Column(name = "A")
 private String a;

 @Column(name = "B")
 private String b;

}

@Embeddable
public class PrimayKey {

 private PartitionKey key;

 @Column(name = "C")
 private String c;

}

Please refer this sample entity for more info.



来源:https://stackoverflow.com/questions/42283636/kundera-persistence-entity-definition-with-partition-key-and-cluster-key

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!