我正在使用datanucleus JDO API来持久化对象。 我的orm文件看起来像这样:
<class name="MyClass" table="mytable">
<inheritance strategy="complete-table"/>
<field name="id" column="id" primary-key="true" value- strategy="AUTO_INCREMENT"/>
</class>
我有
的继承层次结构@PersistenceCapable
public class MyClass extends NonAbstractMyClassParent {
}
public class NonAbstractMyClassParent extends AbstractMyClassParent
{
}
public class AbstractMyClassParent
{
private Long id;
}
id在MyClassAbstractParent中定义。 MyClassParent在数据库中没有相应的表。
当我尝试坚持MyClass时,我得到以下错误。我试着让MyClassParent也抽象但我仍然得到同样的错误。 有什么见解吗? TIA
javax.jdo.JDOException: Metadata for member "com.xxx.MyClass.id" is attempting to illegally override the primary-key setting of its "root" metadata definition (annotations or ".jdo" XML file). You must specify primary-key information in the "root" metadata definition
at org.datanucleus.api.jdo.JDOPersistenceManagerFactory.initialiseMetaData(JDOPersistenceManagerFactory.java:772)
at org.datanucleus.api.jdo.JDOPersistenceManagerFactory.(JDOPersistenceManagerFactory.java:564)
at org.datanucleus.api.jdo.JDOPersistenceManagerFactory.createPersistenceManagerFactory(JDOPersistenceManagerFactory.java:308)
at org.datanucleus.api.jdo.JDOPersistenceManagerFactory.getPersistenceManagerFactory(JDOPersistenceManagerFactory.java:217)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at javax.jdo.JDOHelper$16.run(JDOHelper.java:1975)
答案 0 :(得分:1)
移动
<field name="id" column="id" primary-key="true" value- strategy="AUTO_INCREMENT"/>
定义该字段的类,即AbstractMyClassParent
(同时也将其标记为持久性)。