spring-projects / spring-projects/spring-data-cassandra

Refactor primary key annotations [DATACASS-361]

Open
#530 1 comment 0 reactions 1 assignee View on GitHub

@mp911de is already working on this.

Since Dec 31, 2020.

in: mapping type: task
Dominant language
Java
Stars
400
Forks
318
PR merge metrics
No merged PRs in 30d

Description

Mark Paluch opened DATACASS-361 and commented

Today's @PrimaryKey, @Id and @PrimaryKeyColumn lead to ambiguity which types to use.

  • @Id: applied on field/property level to mark the primary key/identified
  • @PrimaryKey: similar to @Id but with column name property
  • @PrimaryKeyColumn: column name, ordering and primary key type properties

A typical compound key entity looks like:

@PrimaryKeyClass
class PersonKey {
 @PrimaryKeyColumn(name="first_name", type=PARTITIONED, ordinal = 1) String firstname;
 @PrimaryKeyColumn(type=CLUSTERED, ordinal = 2) String lastname;
}

@Table
class Person {
  @PrimaryKey PersonKey key;
  @Column("fieldname") String fieldname;
}

or 

@Table
class Person {
  @Id PersonKey key;
  @Column("fieldname") String fieldname;
}

and a simple key entity:


@Table
class Person {
  @PrimaryKey String key;
  @Column("fieldname") String fieldname;
}

or 

@Table
class Person {
  @Id String key;
  @Column("fieldname") String fieldname;
}

The code raises following questions:

  1. When to use @Id and when @PrimaryKey?
  2. Why is it that @Column cannot be applied to @Id properties?
  3. PrimaryKeyColumn declares properties that can be left empty, depending on the primary key type
  4. Are all annotations required?
Proposal
  1. Deprecate @PrimaryKeyColumn in favor of @PartitionKey(value [optional, ordinal]) and @ClusteringKey(value [optional, ordinal], ordering) that can be combined with @Column. @PrimaryKeyColumn support can remain active and the new annotations can be built as composed annotations
  2. Deprecate @PrimaryKey in favor of @Id that can be combined with @Column.

No further details from DATACASS-361

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.