开发者

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.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜