Thanos
Thanos

Reputation: 633

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?

Upvotes: 2

Views: 497

Answers (2)

Bozho
Bozho

Reputation: 597402

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

Upvotes: 4

DataNucleus
DataNucleus

Reputation: 15577

You have to annotate it (or mark it in orm.xml) as an Entity ... for all classes that are required to be persistable

Upvotes: 1

Related Questions