I have a typical Person-Address entity relationship. After I query the datastore for Person, I then query Person for the key of address. The key (i.e. addrKey
, see below) always returns as null. But I look in the datastore, I see both Person and Address entities, with their keys. So clearly the line Key addrKey = (Key) person.getProperty("address")
is not doing what I think it should be doing. Any ideas how to fix this?
DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
Map<Key, Entity> entities = datastore.get(keys);
List<Person> result = new ArrayList<Person>();
Iterator<Entry<Key, Entity>> it = entities.entrySet().iterator();
while (it.hasNext()) {
Map.Entry<Key, Entity> ent = it.next();
final Entity person = ent.getValue();
Key key = person.getKey();
name = (Long) person.getProperty("name");
Address address = getAddress(datastore, person);
...
}
private Address getAddress(DatastoreService datastore, Entity person) {
Key addrKey = (Key) person.getProperty("address");
try {
Entity d = datastore.get(addrKey);
String street = (String) d.getProperty("street");
…
}