Note that there are some explanatory texts on larger screens.

plurals
  1. POEquivalent of a repeated NDB StructuredProperty in JPA/JDO on Google App Engine
    primarykey
    data
    text
    <p>A list of <code>StructuredProperties</code> in NDB is modelled by a number of repeated properties, one repeated property per property of the <code>StructuredProperty's</code> model class. (See here: <a href="https://developers.google.com/appengine/docs/python/ndb/properties#structured." rel="nofollow">https://developers.google.com/appengine/docs/python/ndb/properties#structured.</a>)</p> <p>The closed equivalent I have found with JPA on Google App Engine is an <code>@Embedded</code> list of <code>@Embeddables</code>. 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: <a href="http://datanucleus-appengine.googlecode.com/svn-history/r979/trunk/src/com/google/appengine/datanucleus/StoreFieldManager.java" rel="nofollow">http://datanucleus-appengine.googlecode.com/svn-history/r979/trunk/src/com/google/appengine/datanucleus/StoreFieldManager.java</a>). (For long lists, this generates rows with many, many columns, for example.)</p> <p>Is there an easy built-in way to copy NDB's way to cope with repeated composite values using JPA or JDO?</p> <p>ADDED:</p> <p>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: <a href="http://code.google.com/p/objectify-appengine/wiki/Entities#Embedding" rel="nofollow">http://code.google.com/p/objectify-appengine/wiki/Entities#Embedding</a>, which is the way I want to achieve with JPA (or JDO):</p> <p>For convenience, I am copying their example here:</p> <pre><code>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&lt;LevelOne&gt; ones = new ArrayList&lt;LevelOne&gt;(); } </code></pre> <p>Using this setup, run the following code:</p> <pre><code>EntityWithEmbeddedCollection ent = new EntityWithEmbeddedCollection(); for (int i=1; i&lt;=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); </code></pre> <p>The resulting row layout (using repeated properties on the Datastore level) is then:</p> <p>ones.foo: ["foo1", "foo2", "foo3", "foo4"]</p> <p>ones.two.bar: ["bar1", "bar2", "bar3", "bar4"]</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload