开发者

Inheritance of JPA Entities

开发者 https://www.devze.com 2023-02-02 10:09 出处:网络
I have a question. Lets say I have an 开发者_高级运维Entity Class called BaseEntity. I annotate this class with @Entity as follows.

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

0

精彩评论

暂无评论...
验证码 换一张
取 消