MountainClimb / datanucleus-appengine

Automatically exported from code.google.com/p/datanucleus-appengine
0 stars 0 forks source link

Embedding a persistance capable object that has a primary key id field result in an exception #195

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago

-------------- Parent Class ---------
@PersistenceCapable(identityType=IdentityType.DATASTORE, detachable="true")
public class Parent{

    @PrimaryKey() @Persistent(valueStrategy=IdGeneratorStrategy.IDENTITY)
    private Key primaryKey;

    @Persistent(embedded="true")
    private EmbeddedObj embeddedObj;

}

------------- To be embedded --------------
@PersistenceCapable
public class EmbeddedObj {
    @PrimaryKey
    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
    @Extension(vendorName="datanucleus", key="gae.encoded-pk", value="true")    
    private String embeddedObjKey;
    @Persistent
    @Extension(vendorName="datanucleus", key="gae.pk-id", value="true")
    private Long embeddedObjId;

    @Persistent
    private String value;
}

When persisting the parent class that contains an EmbeddedObj, you get an 
exception:
java.lang.ClassCastException: java.lang.Long cannot be cast to 
package.path.EmbeddedObj
    at package.path.Parent.jdoReplaceField(Parent.java)
    at org.datanucleus.state.JDOStateManagerImpl.replaceField(JDOStateManagerImpl.java:2687)
    at org.datanucleus.state.JDOStateManagerImpl.replaceField(JDOStateManagerImpl.java:2566)
    at org.datanucleus.store.appengine.DatastorePersistenceHandler.setPostStorePkId(DatastorePersistenceHandler.java:355)
    at org.datanucleus.store.appengine.DatastorePersistenceHandler.insertPostProcess(DatastorePersistenceHandler.java:296)
    at org.datanucleus.store.appengine.DatastorePersistenceHandler.insertObjects(DatastorePersistenceHandler.java:251)
    at org.datanucleus.store.appengine.DatastorePersistenceHandler.insertObject(DatastorePersistenceHandler.java:235)
    at org.datanucleus.state.JDOStateManagerImpl.internalMakePersistent(JDOStateManagerImpl.java:3185)
    at org.datanucleus.state.JDOStateManagerImpl.makePersistent(JDOStateManagerImpl.java:3161)
    at org.datanucleus.ObjectManagerImpl.persistObjectInternal(ObjectManagerImpl.java:1298)
    at org.datanucleus.ObjectManagerImpl.persistObject(ObjectManagerImpl.java:1175)
    at org.datanucleus.jdo.JDOPersistenceManager.jdoMakePersistent(JDOPersistenceManager.java:669)
    at org.datanucleus.jdo.JDOPersistenceManager.makePersistent(JDOPersistenceManager.java:694)
    at package.path.test.TestItem.testEm(TestItem.java:31)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.junit.internal.runners.TestMethodRunner.executeMethodBody(TestMethodRunner.java:99)
    at org.junit.internal.runners.TestMethodRunner.runUnprotected(TestMethodRunner.java:81)
    at org.junit.internal.runners.BeforeAndAfterRunner.runProtected(BeforeAndAfterRunner.java:34)
    at org.junit.internal.runners.TestMethodRunner.runMethod(TestMethodRunner.java:75)
    at org.junit.internal.runners.TestMethodRunner.run(TestMethodRunner.java:45)
    at org.junit.internal.runners.TestClassMethodsRunner.invokeTestMethod(TestClassMethodsRunner.java:66)
    at org.junit.internal.runners.TestClassMethodsRunner.run(TestClassMethodsRunner.java:35)
    at org.junit.internal.runners.TestClassRunner$1.runUnprotected(TestClassRunner.java:42)
    at org.junit.internal.runners.BeforeAndAfterRunner.runProtected(BeforeAndAfterRunner.java:34)
    at org.junit.internal.runners.TestClassRunner.run(TestClassRunner.java:52)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:45)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)

If the embeddedObjId field is removed from EmbeddedObj, the problem goes away.

Original issue reported on code.google.com by arnold.m...@gmail.com on 25 Feb 2010 at 7:57

GoogleCodeExporter commented 8 years ago
Caused by the GAE plugin hack of reusing StoreFieldManager for multiple objects.

Original comment by googleco...@yahoo.co.uk on 29 Jul 2011 at 8:17

GoogleCodeExporter commented 8 years ago
SVN trunk works fine on this

Original comment by googleco...@yahoo.co.uk on 29 Jul 2011 at 8:37