google-code-export / morphia

Automatically exported from code.google.com/p/morphia
1 stars 0 forks source link

Polymorphic lazy reference #364

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What version are you using? (0.99/2.6.5/1.8.2)

Please include a stack trace below:

We are trying to create a module based on morphia with a specific 
collection (ie: ShapeContainer) acting as index for a number of other 
collections. Those collection classes inherit from an abstract base 
entity class (ie: Shape). So we need to create a member (on the 
ShapeContainer) that holds a lazy reference to various shape kinds. You may 
find the classes attached.

We manage to insert the sample data to the db without any problems. 
When we try to retrieve them, we receive the error below. Note that 
this happens when we try to fetch the shape from the shapecontainer 
(actually initialize the lazy entity reference): 

java.lang.RuntimeException: collection names don't match for key and 
class: Shape != Circle 
        at com.google.code.morphia.DatastoreImpl.getByKey(DatastoreImpl.java: 
517) 
        at 
com.google.code.morphia.mapping.lazy.proxy.SerializableEntityObjectReferenc 
e.fetch(SerializableEntityObjectReference.java: 
28) 
        at 
com.google.code.morphia.mapping.lazy.proxy.AbstractReference.get(AbstractRe 
ference.java: 
42) 
        at 
com.thoughtworks.proxy.toys.delegate.DelegatingInvoker.delegate(DelegatingI 
nvoker.java: 
127) 
        at 
com.thoughtworks.proxy.toys.hotswap.HotSwappingInvoker.delegate(HotSwapping 
Invoker.java: 
115) 
        at 
com.thoughtworks.proxy.toys.hotswap.HotSwappingInvoker.invoke(HotSwappingIn 
voker.java: 
87) 
        at 
com.google.code.morphia.mapping.lazy.NonFinalizingHotSwappingInvoker.invoke 
(NonFinalizingHotSwappingInvoker.java: 
25) 
        at com.thoughtworks.proxy.factory.AbstractProxyFactory 
$CoincidentalInvocationHandlerAdapter.invoke(AbstractProxyFactory.java: 
96) 
        at morphia.sample.Shape$$EnhancerByCGLIB$ 
$2f94452c.toString(<generated>) 
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
        at 
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java: 
39) 
        at 
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImp 
l.java: 
25) 
        at java.lang.reflect.Method.invoke(Method.java:597) 
        at 
com.thoughtworks.proxy.toys.delegate.DelegatingInvoker.invokeOnDelegate(Del 
egatingInvoker.java: 
164) 
        at 
com.thoughtworks.proxy.toys.delegate.DelegatingInvoker.invoke(DelegatingInv 
oker.java: 
116) 
        at 
com.thoughtworks.proxy.toys.dispatch.DispatchingInvoker.invoke(DispatchingI 
nvoker.java: 
120) 
        at com.thoughtworks.proxy.factory.AbstractProxyFactory 
$CoincidentalInvocationHandlerAdapter.invoke(AbstractProxyFactory.java: 
96) 
        at morphia.sample.Shape$$EnhancerByCGLIB$ 
$ee934fb3.toString(<generated>) 
        at java.lang.String.valueOf(String.java:2826) 
        at java.io.PrintStream.println(PrintStream.java:771) 
        at morphia.sample.ShapesTest.testListContainers(ShapesTest.java:49) 
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
        at 
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java: 
39) 
        at 
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImp 
l.java: 
25) 
        at java.lang.reflect.Method.invoke(Method.java:597) 
        at junit.framework.TestCase.runTest(TestCase.java:154) 
        at junit.framework.TestCase.runBare(TestCase.java:127) 
        at junit.framework.TestResult$1.protect(TestResult.java:106) 
        at junit.framework.TestResult.runProtected(TestResult.java:124) 
        at junit.framework.TestResult.run(TestResult.java:109) 
        at junit.framework.TestCase.run(TestCase.java:118) 
        at 
org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3 
TestReference.java: 
130) 
        at 
org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java: 
38) 
        at 
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestR 
unner.java: 
467) 
        at 
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestR 
unner.java: 
683) 
        at 
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner 
.java: 
390) 
        at 
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunne 
r.java: 
197)

The above error only appears when the @Reference from ShapeContainer 
towards Shape is marked as lazy.

Original issue reported on code.google.com by Christof...@gmail.com on 20 Dec 2011 at 8:10

Attachments:

GoogleCodeExporter commented 9 years ago
We tried to trace the problem at the 0.99.1-SNAPSHOT source code of morphia 
project. So with a help of a coworker we made some changes that seem to cope 
with our case.

You may find attached the diff generated file from svn. There are some quick 
notes at each code fragment that we made.

Please tell us your opinion on this case when you have time.

We hope that this would be helpfull for the project eitherway.

Original comment by Christof...@gmail.com on 20 Dec 2011 at 12:52

Attachments: