1

我有以下 @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 :

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

4

2 回答 2

1

感谢您在评论中回答这个 Cytemax。我在这里找到了更多澄清信息: http ://openjpa.apache.org/builds/1.0.0/apache-openjpa-1.0.0/docs/manual/manual.html#jpa_overview_pc_identitycls

The example given doesn't use annotations but you mentioned them in your comments. Kind of an odd thing for openJPA to need but as I view the table and java object hierarchy in my mind it sort of makes sense.

于 2013-11-13T15:41:53.237 回答
0

My @Entity class must have an @IdClass(SuperClassPK.class), because my primary key contains two properties (attr1 & attr2).

This @IdClass declare the two properties and must override the "equals" and "hashcode" method.

Maybe this will help someone else ;).

于 2019-11-06T14:49:04.203 回答