Hello,
I have the following parent child relationship (with getter/setter for each field)
***********************************************************************
class ParentClass {
@Id
private Long id;
}
class ChildClass {
@Parent
private Key<ParentClass> parent;
private int value;
}
***********************************************************************
Now, I persist the ParentClass and the ChildClass instances like below (using com.googlecode.objectify.helper.DAOBase)
***********************************************************************
// Persist the parent entity.
ParentClass pClass = new ParentClass();
ofy().put(pClass);
// Persist the child entity.
ChildClass cClass = new ChildClass();
Key<ParentClass> pKey = new Key<ParentClass>(ParentClass.class, pClass.getId());
cClass.setParent(pKey);
cClass.setValue(100);
ofy().put(cClass);
***********************************************************************
It works fine till here and I can see the data in datastore. Now, I try to retrieve the child and parent from datastore, like below.
***********************************************************************
// Retrieve child entity *based on its value*
Query<ChildClass> query = ofy.query(ChildClass.class).filter("value", 100);
ChildClass objChildClass = query.get();
// Retrieve parent entity from the child.
Key<ParentClass> objParentKey = objChildClass.getParent();
ParentClass objParentClass = ofy.get(ParentClass.class, objParentKey.getId());
***********************************************************************
Now, retrieving the parent entity from the child entity seems to fail for me (ie, objParentClass is null for me). Am I doing something wrong?