First of all sorry if this is the second topic with a similar issue. I already posted a similar topic but I can't see it in the group (it has already been several hours) so I'm posting again. I had many problems porting my GAE app to Objectify 3.0 from 2.2.3 with Key serialization when com.googlecode.objectify.Key (Objectify Key) started using com.google.appengine.api.datastore.Key (GAE Key).
I use an application on a non-GAE server to backup some data (via a Hessian-service implemented on GAE) from my APP engine application datastore. The data is loaded from the datastore as objects which are then serialized by Hessian and sent to the non-GAE service. The data is then stored in an object database. The data can be restored (read from the local object database sent to the GAE application and stored to the datastore). The restoring step fails with the message:
java.lang.NullPointerException
at com.google.appengine.api.datastore.KeyTranslator.convertToPb(KeyTranslator.java:55)
at com.google.appengine.api.datastore.EntityTranslator.convertToPb(EntityTranslator.java:34)
at com.google.appengine.api.datastore.AsyncDatastoreServiceImpl.put(AsyncDatastoreServiceImpl.java:429)
at com.googlecode.objectify.impl.AsyncObjectifyImpl.put(AsyncObjectifyImpl.java:255)
I analyzed the decompiled Key code and came to the conclusion that the problem lies in the fact that the appId private variable is not properly retrieved from the server when the GAE Key instance is serialized by Hessian. In fact the appId variable is only set upon Java serialization (the writeObject method).
Another issue is that Java serialization of Key relies on a static object being previously initialized. For example you cannot write this:
Key key = KeyFactory.createKey("banana", (5L));
in a non-GAE application if you have not initialized a LocalServiceTestHelper instance. It dies in the following manner:
java.lang.NullPointerException: No API environment is registered for this thread.
at com.google.appengine.api.datastore.DatastoreApiHelper.getCurrentAppId(DatastoreApiHelper.java:108)
at com.google.appengine.api.datastore.DatastoreApiHelper.getCurrentAppIdNamespace(DatastoreApiHelper.java:118)
at com.google.appengine.api.datastore.Key.<init>(Key.java:51)
at com.google.appengine.api.datastore.Key.<init>(Key.java:37)
at com.google.appengine.api.datastore.KeyFactory.createKey(KeyFactory.java:46)
at com.google.appengine.api.datastore.KeyFactory.createKey(KeyFactory.java:31)
This serialization issue is significant on Android applications that use classes containing Key instances which are shared between Activities since the transfer of objects between Activities uses Java Serialization. I believe that the problem lies with the Gae Key but the question remains: Was it really necessary to include GAE Key in Objectify Key? Can something be done about it? Before the change everything worked fine, of course.
Also, if anyone has the same problems, she can star this issue:
http://code.google.com/p/googleappengine/issues/detail?id=4966Best regards.