I load a top-level object with no activation (depth 0). Then I tried to activate the second-level object I got an exception.
ObjectDatastore datastore = new AnnotationObjectDatastore(false);
Fan datastoreFan = datastore.find().type(Fan.class).activate(0).addFilter(
"id", FilterOperator.EQUAL, fan.getId()).returnUnique().now();
assertTrue(datastoreFan.getName().equals("Me"));
assertTrue(datastoreFan.getConcerts().size() == 1);
assertTrue(datastoreFan.getConcerts().get(0).getId() != null);
assertTrue(datastoreFan.getConcerts().get(0).getPrice() == null);
// Try to activate all the concerts (see stack trace)
datastore.activateAll(datastoreFan.getConcerts());
assertTrue(datastoreFan.getConcerts().get(0).getPrice() != null);
// Try to activate only the first concert (same stack trace)
datastore.activate(datastoreFan.getConcerts().get(0));
assertTrue(datastoreFan.getConcerts().get(0).getPrice() != null);
java.lang.IllegalStateException: Problem translating field private final java.util.List com.test.model.Concert.bands with properties [[SimpleProperty value=[com_test_model_Band(201)] path=bands indexed=false]]
at com.google.code.twig.translator.FieldTranslator.decodeField(FieldTranslator.java:157)
at com.google.code.twig.standard.TranslatorObjectDatastore$ObjectFieldTranslator.decodeField(TranslatorObjectDatastore.java:963)
at com.google.code.twig.translator.FieldTranslator.decode(FieldTranslator.java:122)
at com.google.code.twig.standard.StandardDecodeCommand.entityToInstance(StandardDecodeCommand.java:119)
at com.google.code.twig.standard.StandardDecodeCommand.keysToInstances(StandardDecodeCommand.java:235)
at com.google.code.twig.standard.StandardUntypedMultipleLoadCommand.now(StandardUntypedMultipleLoadCommand.java:20)
at com.google.code.twig.standard.TranslatorObjectDatastore.doRefreshActivate(TranslatorObjectDatastore.java:731)
at com.google.code.twig.standard.TranslatorObjectDatastore.activateAll(TranslatorObjectDatastore.java:768)
at com.test.MyConcurrencyTest.testAssociation(MyConcurrencyTest.java:73)
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.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:30)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: java.lang.ClassCastException: com.test.model.Concert cannot be cast to java.util.List
at com.google.code.twig.standard.CollectionTranslator.createCollection(CollectionTranslator.java:141)
at com.google.code.twig.standard.CollectionTranslator.decode(CollectionTranslator.java:47)
at com.google.code.twig.translator.ChainedTranslator.decode(ChainedTranslator.java:75)
at com.google.code.twig.translator.FieldTranslator.decodeField(FieldTranslator.java:152)
... 33 more
I also wonder if it's possible after you loaded an instance to activate until a certain depth. For instance you get a fan, then you want to activate the concert but not the bands.