好的,这是一个简单的例子:
我有一个这样定义的抽象父类(super class):
abstract public class AbstractSuperEntity {
private char someFlag;
public void setSomeFlag(char flagValue) {
this.someFlag = flagValue;
}
public char getSomeFlag() {
return this.someFlag;
}
}
我所有的 @Entity
类都继承自它。一个例子可能是:
@Entity
@Table("SOME_ENTITY")
public class SomeEntity extends AbstractSuperEntity {
@Column(name="ID");
private Long id;
etc.
}
AbstractSuperEntity
中的someFlag
属性是否需要有@Transient
?
我试过有和没有,似乎没有任何区别。但我只是害怕我错过了一些东西。
编辑感谢所有快速回答。
一位同事还向我指出了 JPalace.org 上的 JPA 教程,特别是 ORM and JPA Concepts 上的页面其中包含以下部分:
Non-Entity Superclasses
Entities may also extend non-entity superclasses. These superclasses can be either abstract or concrete. The state of non-entity superclasses is always non-persistent. Thus, any state inherited from the non-entity superclass by an entity class is non-persistent.
Similarly to mapped superclasses, non-entity superclasses may not be used subject to queries. Mapping and relationship annotation present in a non-entity superclasses are ignored. Again, this is beacause there is no correponding database table to which the querying operations or relationships can be applied.
最佳答案
不,不需要 @Transient
注释,因为您的 AbstractSuperEntity
既不是 MappedSuperClass
, 也不是 Entity
.如果您希望它包含映射信息(继承的),则必须使用这些注释之一对其进行注释。
关于java - 我需要在未映射的父类(super class)属性上使用 @Transient 注释吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23903628/