Shane Courtrille
Shane Courtrille

Reputation: 14097

Hibernate @Id via inheritance

I'm trying to duplicate something you can do in .Net but not having much luck.

Is the following not possible in Java or am I just missing something? When I run it I get told there is no identifier specified for entity Group.

public abstract class RCEntity
{
   @Id @GeneratedValue
   private int id;

   //getters & setters
}

@Entity 
public class Group extends RCEntity {
}

Upvotes: 15

Views: 4796

Answers (2)

oksayt
oksayt

Reputation: 4365

From this section in the docs:

Any class in the hierarchy non annotated with @MappedSuperclass nor @Entity will be ignored.

Upvotes: 5

William
William

Reputation: 13632

Add the annotation @MappedSuperclass to your super class, i.e.

@MappedSuperclass
public abstract class RCEntity
{
   @Id @GeneratedValue
   private int id;

   //getters & setters
}

Upvotes: 23

Related Questions