我有一个典型的人地址实体关系。在查询数据存储中的 Person 之后,我会查询 Person 的地址键。键(即addrKey
,见下文)始终返回为 null。但是我查看数据存储区,我看到了 Person 和 Address 实体,以及它们的键。很明显,这条线Key addrKey = (Key) person.getProperty("address")
没有做我认为应该做的事情。任何想法如何解决这一问题?
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");
…
}