-1

I am using datanucleus JDO API for persisting objects. my orm file looks like this:

   <class name="MyClass" table="mytable">
        <inheritance strategy="complete-table"/>
        <field name="id" column="id" primary-key="true" value- strategy="AUTO_INCREMENT"/>
   </class>

I have an inheritance hierarchy of

@PersistenceCapable
public class MyClass extends NonAbstractMyClassParent {
}

public class NonAbstractMyClassParent extends AbstractMyClassParent    
{
}

public class AbstractMyClassParent    
{
  private Long id;
}

The id is defined in the MyClassAbstractParent. MyClassParent does NOT have a corresponding table in the database.

When I try to persist the MyClass, I get the below error. I tried making the MyClassParent also abstract but still I get the same error. Any insights please? 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)

YesR
  • 100
  • 1
  • 6
  • 1
    So those superclasses aren't defined as persistent capable? in which case you can't use "id" since it is not persistent. If they are persistence capable, then you have to define the strategy etc in the root (as the message says) – Neil Stockton Oct 11 '15 at 06:43
  • Thank you. Made some progress by using subclass-table strategy and making the classes persistableaware. However, the parent class is part of a different directory and now seeing an error "java.io.FileNotFoundException: file:/Users/subbuvedula/.m2/repository/com/xxx/search/1.0-SNAPSHOT/search-1.0-SNAPSHOT.jar!/com/xxx/model/AbstractMyClassParent.class (No such file or directory) during enhancement – YesR Oct 11 '15 at 07:18
  • i dont see what PersistenceAware has to do with anything here; that is for classes that need to set persistable fields. So some file isn't found ... only you know what is in the CLASSPATH, and what enhancer options are defined – Neil Stockton Oct 11 '15 at 07:39
  • Thanks. After making all the necessary classes persistablecapable, and setting the "targetDirectory" property, i am back with the same exception but this time on the parent: javax.jdo.JDOException: Metadata for member "com.xxx. AbstractMyClassParent.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. There no more 'root' than AbstractMyClassParent and wondering what I am missing. – YesR Oct 11 '15 at 07:55
  • The ROOT is the root class in the inheritance tree. Where the PK should be defined. You CANNOT DEFINE "primary-key" in a subclass ... as the MESSAGE says – Neil Stockton Oct 11 '15 at 07:58
  • Yes Neil. That was where my id was defined, at the root class. – YesR Oct 11 '15 at 08:10
  • 1
    Errm, no IT ISN't. You have no METADATA defining that FIELD as "primary-key" in the ROOT class. You put "primary-key" definition in METADATA for the MyClass. Wrong – Neil Stockton Oct 11 '15 at 08:14

1 Answers1

1

Move

<field name="id" column="id" primary-key="true" value- strategy="AUTO_INCREMENT"/>

to the class that defines that field, namely AbstractMyClassParent (whilst also marking it as persistence capable).

Neil Stockton
  • 11,383
  • 3
  • 34
  • 29
  • Niel, thank you. I have done that but without luck. Have had issues with data nucleus. It could be my poor understanding of how it works. After having spent 2 days on datanucleus, have switched to eclipselink JPA. It was a breeze so far. Thanks for your support. – YesR Oct 11 '15 at 17:56
  • EclipseLink doesn't do JDO so your comment makes no sense ; they are not comparable. If you have a problem I'd suggest that you provide *complete* information (which you haven't here) otherwise nobody will be able to help you. – Neil Stockton Oct 11 '15 at 18:05