我有以下@MappedSuperClass和@Entity:
@MappedSuperclass
public class SuperClass implements Serializable {....}
@Entity
@Inheritance(strategy=InheritanceType.TABLE_PER_CLASS)
@Table(name = "TABLE1")
public class Table1 extends SuperClass implements Serializable {...}
@Entity
@Inheritance(strategy=InheritanceType.TABLE_PER_CLASS)
@Table(name = "TABLE2")
public class Table2 extends SuperClass implements Serializable {...}
在数据库中,两个表都具有相同的列,因此我的所有属性都在SuperClass中:
@Id
private String attr1;
@Id
private String attr2;
@Column(name="DATA")
private String data;
// getters and setters
但是当我尝试使用@entity(table1或table2)之一执行查询时,出现OpenJPA错误:
Error pre-processing class table1 with weblogic.deployment.PersistenceUnitInfoImpl$ClassPreProcessorImpl@205c54b'
<openjpa-1.1.0-r422266:657916 fatal user error>
org.apache.openjpa.util.MetaDataException: Type "class SuperClass" with application identity and no superclass does not declare an id class.
This type is not eligible for builtin identity, so it must declare an id class.
我不明白为什么在@Entity类中找不到@Id属性。
如果有人有什么想法,请随时帮助我:)
问候,
Cytemax
感谢您在评论中回答此Cytemax。我在这里找到了更多需要澄清的信息:http://openjpa.apache.org/builds/1.0.0/apache-openjpa-1.0.0/docs/manual/manual.html#jpa_overview_pc_identitycls
给出的示例不使用注释,但是您在注释中提到了注释。 openJPA需要某种奇怪的东西,但是当我在脑海中查看表和Java对象层次结构时,这是有道理的。
我的@Entity类必须具有@IdClass(SuperClassPK.class),因为我的主键包含两个属性(attr1和attr2)。
此@IdClass声明两个属性,并且必须重写“ equals”和“ hashcode”方法。
也许这会帮助别人;)。