How do i get all child entities in Google App Engine (Low-level API)
-
14-09-2019 - |
Question
I'm using the low-level API in Google App Engine for Java and want to get all the child entities of a particular parent entity:
Given the following graph:
Parent (1)
|
+ --- Child A (2)
| |
| + --- Child B (3)
|
+ --- Child A (4)
I want a list like the following
[Child A (2), Child B (3), Child A (4)]
Here is my best attempt:
Entity pe = new Entity("parent");
Entity c1 = new Entity("childA", pe.getKey());
Entity c2 = new Entity("childB", c1.getKey());
Entity c3 = new Entity("childA", pe.getKey());
// storage code left out for brevity
Key parentKey = KeyFactory.createKey(null, "parent", 1);
// According to documentation this should work (but does not)
PreparedQuery q = datastore.prepare(new Query(parentKey));
Solution
I found out that this is a known bug in the local development server. When uploading to google it works fine
OTHER TIPS
Wouldn't getKey()
be a method, not a property (ent.getKey()
, not ent.getKey
?
Also, isn't parentKey
the same as pe.getKey()
?
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow