javax.persistence注释和继承

javax.persistence注释和继承,java,hibernate,jpa,annotations,Java,Hibernate,Jpa,Annotations,我有4个持久性类,它们都有相同的字段(确切地说),它们之间唯一的3个区别是1)类名,2)表名和3)数据。我知道这对一些人来说可能很奇怪,但相信我,我有一个很好的理由不在这里讨论 现在,我正在使用hibernate注释来配置我的类,其工作原理如下: @Entity @Table(name = "store") public class Store { @Id @Column(name = "unique_id") protected String id; @Column protecte

我有4个持久性类,它们都有相同的字段(确切地说),它们之间唯一的3个区别是1)类名,2)表名和3)数据。我知道这对一些人来说可能很奇怪,但相信我,我有一个很好的理由不在这里讨论

现在,我正在使用hibernate注释来配置我的类,其工作原理如下:

@Entity
@Table(name = "store")
public class Store
{
 @Id
 @Column(name = "unique_id")
 protected String id;
 @Column
 protected String category;
 ...
}
。。对于一个单独的类来说,这是可行的,但是有许多字段需要映射,我想对所有四个类似的类一次完成这一切,即:

public class StoreBase
{
 @Id
 @Column(name = "unique_id")
 protected String id;
 @Column
 protected String category;
 ...
}

@Entity
@Table(name = "store1")
public class Store1 extends StoreBase
{}

@Entity
@Table(name = "store2")
public class Store2 extends StoreBase
{}

@Entity
@Table(name = "store3")
public class Store3 extends StoreBase
{}

@Entity
@Table(name = "store4")
public class Store4 extends StoreBase
{}
但是,尝试此操作时,我遇到以下异常:

Caused by: org.hibernate.AnnotationException: No identifier specified for entity: package.entities.Store1
 at org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:672)
 at org.hibernate.cfg.AnnotationConfiguration.processArtifactsOfType(AnnotationConfiguration.java:546)
 at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:291)
 at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1292)
 at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:867)
我猜这是因为超类没有被搜索标识符

在这种情况下,有没有办法利用继承权

谢谢你,保罗

@MappedSuperclass
public class StoreBase

有关更多信息,请参阅。

请查看

更改标签。这不是关于hibernate注释,而是关于jpa使用hibernate