What I'm doing wrong: java.lang.IllegalStateException: Unregistered type

123 views
Skip to first unread message

Pavel Bernshtam

unread,
Dec 5, 2012, 3:12:24 PM12/5/12
to twig-p...@googlegroups.com
Hi!
I'm trying to start working with twig in Gaelyk application.
I'm using twig 2.0:

        <dependency>
            <groupId>com.google.code.twig</groupId>
            <artifactId>twig-persist</artifactId>
            <version>2.0-rc</version>
        </dependency>

But even for the simplest class

class SimpleClass {
    int i=5
}

in a test

 void testStore() {
        ObjectDatastore datastoring = new AnnotationObjectDatastore();
        SimpleClass s = new SimpleClass()
        datastoring.store(s)

    }

I receive

java.lang.IllegalStateException: Unregistered type class SimpleClass
at com.google.code.twig.configuration.DefaultConfiguration.typeToName(DefaultConfiguration.java:129)
at com.google.code.twig.configuration.DefaultConfiguration.typeToKind(DefaultConfiguration.java:104)
at com.google.code.twig.standard.StandardCommonStoreCommand.instanceToEntity(StandardCommonStoreCommand.java:321)
at com.google.code.twig.standard.StandardCommonStoreCommand.instanceToKey(StandardCommonStoreCommand.java:243)
at com.google.code.twig.standard.StandardSingleStoreCommand.now(StandardSingleStoreCommand.java:43)
at com.google.code.twig.standard.TranslatorObjectDatastore.store(TranslatorObjectDatastore.java:188)
at com.google.code.twig.ObjectDatastore$store.call(Unknown Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:42)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
at TestTwig.testStore(TestTwig.groovy:16)

John Patterson

unread,
Dec 9, 2012, 5:23:17 AM12/9/12
to twig-p...@googlegroups.com
The RC requires all classes to be registered before use with this static method:

ObjectDatastoreFactory.register(MyClass.class);

this change is to avoid full package names being used in the "kind".  It would be nice to have some automated way to add many classes, such as a package scan.  There have been performance problems with this on GAE but I believe that placing all your classes in a jar fixes it.

Pavel Bernshtam

unread,
Dec 10, 2012, 2:10:37 AM12/10/12
to twig-p...@googlegroups.com
Thank you, but after registration I receive

java.lang.NullPointerException: No API environment is registered for this thread.
at com.google.appengine.api.datastore.DatastoreApiHelper.getCurrentAppId(DatastoreApiHelper.java:86)
at com.google.appengine.api.datastore.DatastoreApiHelper.getCurrentAppIdNamespace(DatastoreApiHelper.java:96)
at com.google.appengine.api.datastore.Key.<init>(Key.java:106)
at com.google.appengine.api.datastore.Key.<init>(Key.java:90)
at com.google.appengine.api.datastore.Key.<init>(Key.java:86)
at com.google.appengine.api.datastore.Entity.<init>(Entity.java:125)
at com.google.appengine.api.datastore.Entity.<init>(Entity.java:106)
at com.google.code.twig.util.Entities.createEntity(Entities.java:45)
at com.google.code.twig.standard.StandardEncodeCommand.createEntity(StandardEncodeCommand.java:31)
at com.google.code.twig.standard.StandardCommonStoreCommand.instanceToEntity(StandardCommonStoreCommand.java:391)
at com.google.code.twig.standard.StandardCommonStoreCommand.instanceToKey(StandardCommonStoreCommand.java:243)
at com.google.code.twig.standard.StandardSingleStoreCommand.now(StandardSingleStoreCommand.java:43)
at com.google.code.twig.standard.TranslatorObjectDatastore.store(TranslatorObjectDatastore.java:188)
at com.google.code.twig.ObjectDatastore$store.call(Unknown Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:42)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
at TestTwig.testStore(TestTwig.groovy:19)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
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.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.junit.runner.JUnitCore.run(JUnitCore.java:157)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:76)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:195)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:63)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)

John Patterson

unread,
Dec 10, 2012, 2:14:23 AM12/10/12
to twig-p...@googlegroups.com
This is an exception thrown from the GAE dev environment saying it has not been set up correctly.

I am guessing that your test case does not set up the test environment correctly.  You can extend LocalDatastoreTest to get started quickly.
Reply all
Reply to author
Forward
0 new messages