我有使用存储功能的实体。这很好,但在某些情况下我不需要此字段(fieldStoreFunc1、fieldStoreFunc2 ..)并且仅在必要时使用 B 类和 fieldStoreFuncs:
@Entity
@Table(name = "table")
@SequenceGenerator(name = "JDE_SEQUENCE", sequenceName = "JDE_SEQUENCE", allocationSize = 1)
public class EntityClass implements Trackable {
@Id
@GeneratedValue(generator = "JDE_SEQUENCE", strategy = GenerationType.SEQUENCE)
private Long id;
@Column(name = "name_field")
private String field1;
@Column(name = "name_field")
private String field2;
@Column(name = "name_field")
private String field3;
......
//read only fields
@Formula("store_func(value)")
private String fieldStoreFunc1;
@Formula("store_func(value)")
private String fieldStoreFunc2;
@Formula("store_func(value)")
private String fieldStoreFunc3;
}
所以我可以把班级分成
class A{
@Column(name = "name_field")
private String field1;
@Column(name = "name_field")
private String field2;
.....
}
class B extends A{
//read only fields
@Formula("store_func(value)")
private String fieldStoreFunc1;
@Formula("store_func(value)")
private String fieldStoreFunc2;
@Formula("store_func(value)")
private String fieldStoreFunc3;
}