0

我必須爲學校開發一個Web應用程序,但我有以下問題:我有一個對象具有幾個屬性,其中一個是具有自定義對象的數組列表。然後我使用objectify將對象放入數據存儲區,但是當我檢查gae儀表板數據存儲區查看器時,它具有所有屬性,但不包含數組存儲區。GAE數據存儲:如何存儲自定義對象的數組列表

要給它是如何工作更好的視野: 這是包含數組列表對象:

public class Competentie implements Serializable { 
    private static final long serialVersionUID = 1L; 
    @Id Long id; 
    private String competentie; 
    List<Stelling> deStellingen = new ArrayList<Stelling>(); 

    public Competentie(String c){ 
     competentie = c; 
    } 

    public Competentie(){} 

    public String getCompetentie(){ 
     return competentie; 
    } 

    public void setCompetentie(String c){ 
     competentie = c; 
    } 

    public void voegStellingToe(Stelling s){ 
     deStellingen.add(s); 
    } 

    public List<Stelling> getStellingen(){ 
     return deStellingen; 
    } 
} 

這裏是我如何把它的數據存儲

public void createCompetentie(String comp){ 
    Competentie c = new Competentie(comp); 
    ofy.put(c); 
} 
莫非

別人的幫助我在這呢?如果有人需要更多信息,請問。

回答

1

看看這裏,在那裏維基: https://code.google.com/p/objectify-appengine/wiki/Entities#Embedding

你使用@Embed在Stelling類?這是我能想到的唯一的事情。他們還有一些需要記住的內容,它們是: 有些事情要記住:

這不支持任何類型的二維結構。 您不能在其他@Embed數組/集合中嵌套@Embed數組/集合。 您不能在@Embed數組/集合中放置數組/集合的本機類型。 但是,您可以在任何數量的@Embed類中嵌套@Embed數組/集合。 您應該初始化集合。空集合或空集合不會寫入數據存儲,因此在加載期間會被忽略。此外,具體實例將按原樣使用,允許您使用比較器或其他狀態初始化集合。

如果上述其中之一爲真,您也可以考慮對deStellingen對象進行searlizing,但是您無法在其上查詢。 https://code.google.com/p/objectify-appengine/wiki/Entities#Serializing

+0

我不能使用@Embed註釋,因爲我使用的是objectify v3,我必須使用該版本。這個版本也有可能嗎? –

+0

在Objectify v3中,您應該可以使用@Embedded註釋。 – stickfigure

+0

指向v3文檔中@embed的鏈接: https://code.google.com/p/objectify-appengine/wiki/IntroductionToObjectify#@Embedded – Michael