Spring 数据 Cassandra 多态性,覆盖列定义

Spring data Cassandra polymorphism, override column definition

我正在创建 classes 的层次结构,目的是对 table 进行非规范化。表很宽,所以为了处理麻烦和错误,我想在父项中声明所有字段,然后更改子项中特定字段的定义。这样我就可以将父项中的普通列重新定义为子项中主键的一部分。

例如:

基本超class

public class A {
  @Column
  protected int age;
}

Class 扩展 A

@Table
public class B extends A {
  @PrimaryKey
  protected K key;
  ...
}

A 的主键,具有 age 列的新定义。

@PrimaryKeyClass
public class K {
  @PrimaryKeyColumn
  private int age;
  @PrimaryKeyColumn
  private int ignore;
}

这似乎行不通。我收到 Multiple definition of identifier 异常。

到目前为止,我只能在父项中声明不会更改的字段,然后在每个子项中声明所有可能更改的字段。我不喜欢这样,因为我必须预先知道可能成为未来主键一部分的每个字段。

将注释放在(父)getter 上并覆盖它们似乎没有做任何事情。

除了在父级中只保留永不改变的列之外,还有什么方法可以解决这个问题?

Putting the annotations on the (parent) getters and overriding those doesn't seem to have done anything.

用@Transient 注释子 getter 做到了!

因此:注释父 getter 而不是字段,使子 getter @Transient,将列定义移动到键中,完成。

从这里开始:

http://docs.datastax.com/en/developer/java-driver/3.1/manual/object_mapper/creating/

One powerful advantage of annotating getter methods is that annotations are inherited from overridden methods in superclasses and superinterfaces; in other words, if a getter method is overridden in a subclass, annotations in both method declarations will get merged together. If duplicated annotations are found during this merge process, the overriding method’s annotations will take precedence over the overridden’s.