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 {
}
Add the annotation @MappedSuperclass to your super class, i.e.
@MappedSuperclass
public abstract class RCEntity
{
@Id @GeneratedValue
private int id;
//getters & setters
}
From this section in the docs:
Any class in the hierarchy non annotated with @MappedSuperclass nor @Entity will be ignored.
精彩评论