2
我有一個典型的人地址實體關係。在查詢Person的數據存儲之後,我查詢Person作爲地址的密鑰。密鑰(即addrKey
,見下文)始終返回爲空。但是我在數據存儲中查看,我看到了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");
…
}
我也有這個沒有身份證問題。但是我設法通過首先將人員放入數據庫來解決此問題,然後創建地址實體並使用最近創建的地址實體的密鑰更新數據庫中的人員實體屬性。但是,如果我需要在交易中同時擁有人員和地址實體,該怎麼辦?如果地址實體不是同時添加的,就像人實體不能被添加(提交)一樣?你如何去做? – kerafill 2015-06-23 17:07:17