简体   繁体   English

等同于Google App Engine中JPA / JDO中重复的NDB StructuredProperty

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

A list of StructuredProperties in NDB is modelled by a number of repeated properties, one repeated property per property of the StructuredProperty's model class. NDB中的StructuredProperties列表由许多重复属​​性建模,其中每个重复属性都是StructuredProperty's模型类的每个属性。 (See here: https://developers.google.com/appengine/docs/python/ndb/properties#structured. ) (请参见此处: https : //developers.google.com/appengine/docs/python/ndb/properties#structured。

The closed equivalent I have found with JPA on Google App Engine is an @Embedded list of @Embeddables . 我在Google App Engine上通过JPA找到的封闭等效项是@Embeddables@Embedded列表。 The storage format, however, is now different. 但是,存储格式现在有所不同。 The GAE/J plugin for JPA generates one column per embedded entity per property of the embedded entity (see here: http://datanucleus-appengine.googlecode.com/svn-history/r979/trunk/src/com/google/appengine/datanucleus/StoreFieldManager.java ). 用于JPA的GAE / J插件为每个嵌入式实体的每个嵌入式实体属性生成一列(请参阅此处: http : //datanucleus-appengine.googlecode.com/svn-history/r979/trunk/src/com/google/appengine /datanucleus/StoreFieldManager.java )。 (For long lists, this generates rows with many, many columns, for example.) (例如,对于长列表,这会生成包含很多列的行。)

Is there an easy built-in way to copy NDB's way to cope with repeated composite values using JPA or JDO? 是否有一种简单的内置方法来复制NDB以使用JPA或JDO处理重复的复合值的方法?

ADDED: 添加:

For those more comfortable with Java than Python, I have found that the Java-based Objectify framework stores collections of embedded classes in the same way as NDB on Python: http://code.google.com/p/objectify-appengine/wiki/Entities#Embedding , which is the way I want to achieve with JPA (or JDO): 对于那些比Python更熟悉Java的人,我发现基于Java的Objectify框架以与Python上的NDB相同的方式存储嵌入式类的集合: http : //code.google.com/p/objectify-appengine/wiki / Entities#Embedding ,这是我要使用JPA(或JDO)实现的方法:

For convenience, I am copying their example here: 为了方便起见,我在此处复制其示例:

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

Using this setup, run the following code: 使用此设置,运行以下代码:

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

The resulting row layout (using repeated properties on the Datastore level) is then: 然后,结果行布局(使用数据存储级别的重复属性)为:

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

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

Google's JDO/JPA plugin definition of embedded collections was specified in https://code.google.com/p/datanucleus-appengine/issues/detail?id=258&can=1&q=embedded&colspec=ID%20Stars%20Type%20Status%20Priority%20FoundIn%20TargetRelease%20Owner%20Summary 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

If you want some other definition of how that is stored (and there are many many ways in which it could be stored) then you raise an issue on that issue tracker of Googles (and if you want the feature sooner rather than later, then provide some resource to implement it) 如果您想要关于存储方式的其他定义(可以有许多种存储方式),那么您会在Google的问题跟踪器上提出一个问题(如果您希望此功能早点而不是晚点,请提供)一些资源来实现它)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM