2009-06-15 61 views
4

我在Google App Engine for Java中使用低級API並想要獲取特定父實體的所有子實體:我如何獲取Google App Engine中的所有子實體

鑑於如下圖:

Parent (1) 
| 
+ --- Child A (2) 
| | 
| + --- Child B (3) 
| 
+ --- Child A (4) 

我要像下面

[Child A (2), Child B (3), Child A (4)] 

下面的列表是我最好的嘗試:

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)); 

回答

3

我發現這是本地開發服務器中的一個已知錯誤。當上傳到谷歌它工作正常

+0

這是一個已知的錯誤?有錯誤跟蹤器的鏈接嗎? – 2014-04-25 15:22:18

0

是不是getKey()是一種方法,而不是屬性(ent.getKey(),而不是ent.getKey

另外,是不是parentKey相同pe.getKey()

+0

謝謝,我修正了錯字。 就pe.getKey()而言,當查詢實際執行時,我只有Id編號,所以我想我會包括我如何得到密鑰。 – 2009-06-15 23:29:47

相關問題