簡體   English   中英

等同於Google App Engine中JPA / JDO中重復的NDB StructuredProperty

[英]Equivalent of a repeated NDB StructuredProperty in JPA/JDO on Google App Engine

NDB中的StructuredProperties列表由許多重復屬​​性建模,其中每個重復屬性都是StructuredProperty's模型類的每個屬性。 (請參見此處: https : //developers.google.com/appengine/docs/python/ndb/properties#structured。

我在Google App Engine上通過JPA找到的封閉等效項是@Embeddables@Embedded列表。 但是,存儲格式現在有所不同。 用於JPA的GAE / J插件為每個嵌入式實體的每個嵌入式實體屬性生成一列(請參閱此處: http : //datanucleus-appengine.googlecode.com/svn-history/r979/trunk/src/com/google/appengine /datanucleus/StoreFieldManager.java )。 (例如,對於長列表,這會生成包含很多列的行。)

是否有一種簡單的內置方法來復制NDB以使用JPA或JDO處理重復的復合值的方法?

添加:

對於那些比Python更熟悉Java的人,我發現基於Java的Objectify框架以與Python上的NDB相同的方式存儲嵌入式類的集合: http : //code.google.com/p/objectify-appengine/wiki / Entities#Embedding ,這是我要使用JPA(或JDO)實現的方法:

為了方便起見,我在此處復制其示例:

import com.googlecode.objectify.annotation.Embed;
import com.googlecode.objectify.annotation.Entity;
import com.googlecode.objectify.annotation.Id;

@Embed
class LevelTwo {
    String bar;
}

@Embed
class LevelOne {
    String foo;
    LevelTwo two
}

@Entity
class EntityWithEmbeddedCollection {
    @Id Long id;
    List<LevelOne> ones = new ArrayList<LevelOne>();
}

使用此設置,運行以下代碼:

EntityWithEmbeddedCollection ent = new EntityWithEmbeddedCollection();
for (int i=1; i<=4; i++) {
    LevelOne one = new LevelOne();
    one.foo = "foo" + i;
    one.two = new LevelTwo();
    one.two.bar = "bar" + i;

    ent.ones.add(one);
}

ofy().save().entity(ent);

然后,結果行布局(使用數據存儲級別的重復屬性)為:

them.foo:["foo1"、"foo2"、"foo3"、"foo4“]

them.two.bar:["bar1"、"bar2"、"bar3"、"bar4“]

https://code.google.com/p/datanucleus-appengine/issues/detail?id=258&can=1&q=embedded&colspec=ID%20Stars%20Type%20Status%20Priority%中指定了Google對嵌入式集合的JDO / JPA插件定義。 20FoundIn%20TargetRelease%20Owner%20Summary

如果您想要關於存儲方式的其他定義(可以有許多種存儲方式),那么您會在Google的問題跟蹤器上提出一個問題(如果您希望此功能早點而不是晚點,請提供)一些資源來實現它)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM