2
在一個簡單的繼承樹,一個抽象的超類有兩個子類。我可以在Hibernate每個層次繼承策略中的子類間重複使用一列嗎?
子類都存儲一個鍵 - 值對,但只有一個會拿着類型加密的字符串,而另一個普通老式字符串。現在
,我的問題是我能做到這一點:
@Entity
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
public abstract Attribute {
@Id
private Integer id;
@Column(name="attribute_key")
private String key;
}
@Entity
public EncryptedAttribute extends Attribute {
@Column(name="attribute_value")
private EncryptedString encryptedValue;
}
@Entity
public UnEncryptedAttribute extends Attribute {
@Column(name="attribute_value")
private String plainValue;
}
加密的字符串和普通字符串都應該結束瞭如同db VARCHAR處理,但我可以存儲與不同的子類中相關的持久化屬性同一列?這將避免在特定行中未使用的列中存儲空值的「瑞士奶酪」副作用。