JDOObjectNotFoundException while trying to get child object in GAE

I developed a data model where there are parent and child objects (one for many). First, I did all the work manually and saved the parent id in the child objects in order to preserve the relationship. Then I decided to use a relationship with the application engine documentation. Now I have a parent with identifier 21 and a child with identifier 1 (I assume that ID is 1 because this child is the only and first child of this parent). Now I'm trying to get the key as: child.getKey ()

And with the same line, I'm trying to get an object with:

Child = pm.getObjectById (Child.class, key);

Somehow I get this error: WARNING: /admin.jsp javax.jdo.JDOObjectNotFoundException: Failed to get an entity of the form Child with the key Child ("Parent (21) / Child (1)")

I know this child exists in this parent. Maybe someone can help me? I researched about it, and nothing appeared ...

+4
source share
1 answer

I found a solution after several hours of trying every opportunity. There are two ways to solve this problem. First of all, if you want to get a child with a key, make sure the key is not a string. It must be a key (com.google.appengine.api.datastore.Key). You can get this key in two different ways:

Key key = new KeyFactory .Builder(Parent.class.getSimpleName(), ParentID) .addChild(Child.class.getSimpleName(), ChildID).getKey(); 

or

 Key key = KeyFactory.stringToKey(keyString); //you can obtain keyString with KeyFactory.keyToString(ChildObject.getKey()); 

Then you can easily use:

 Child child = pm.getObjectById(Child.class, key); 
+4
source

All Articles