Inheritance of JPA Entities
I have a question.
Lets say I have an 开发者_高级运维Entity Class called BaseEntity. I annotate this class with @Entity as follows.
@Entity
public class BaseEntity implements Serializable {
.....
}
If I write another class called Employee that extends BaseEntity as
public class Employee extends BaseEntity{
....
}
and I do not annotate it with @Entity, will my employee class have Entity like behaviour? What I mean to ask is will it become an Entity because its extending my BaseEntity
Or should I always need to annotate a class with @Entity to get Entity like behaviour?
Yes, you have to annotate it as entity. But for your base class you can use @MappedSuperclass
, so that no table is required for it
You have to annotate it (or mark it in orm.xml) as an Entity ... for all classes that are required to be persistable
精彩评论