繁体   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