Spring Boot Cassandra Repository With Composite Primary Key & Not Using Seperate Key Class

20 Views Asked by At

I am using Spring boot cassandra entity classes and repositories, many of my entities/tables have composite primary keys or multiple columns that create the primary key and when extending Spring Data Repository interface the Primary Key has to be a single object which requires me to create a separate key class annotated with @PrimaryKey and doing that distracts or prevents me from having a single entity class which I want, to keep it simple and have all the columns from the table in the same class. Is it possible to have the three fields below that make a composite primary key in the same entity class annotated with @Table and still create a spring repository for the entity like I show in second code snippet?

@PrimaryKeyColumn(name = "stream", ordinal = 0, type = PrimaryKeyType.PARTITIONED)
private int stream;

@PrimaryKeyColumn(name = "entity", ordinal = 1, type = PrimaryKeyType.PARTITIONED)
private int entity;

@PrimaryKeyColumn(name = "date", ordinal = 2, type = PrimaryKeyType.CLUSTERED)
private Date date;

What I want is

public MyRepository extends CassandraRepository<T, ID> 
// but being able to add my 3 primary keys in the entity class. 
0

There are 0 best solutions below