Hi there, 1. From the parent's key, I use
key.addChild(...) to build the full key to the child. Is this the same as the KeyFactory.createKey(...) that you use to build the child key? 2. To get an object without knowing its parent you can run a query on one of more of the child's persistent data members. You will need to have your query such that it returns just the single child that you are after. On Aug 17, 6:19 pm, aprendiz <[email protected]> wrote: > Thanks Jeffrey, but your solution does not work. > > I have solved it this way: > > // 1) Build key parent. > Key kparent = > KeyFactory.createKey(Product.class.getSimpleName(), "product_001"); > > // 2) Build key child. > Key kchild = KeyFactory.createKey(kparent, > Format.class.getSimpleName(), 985); > > Is there any way to get an object without knowing his parent? > > Thanks a lot! > > On 13 ago, 03:56, jeffrey_t_b <[email protected]> wrote: > > > > > > > > > I think that you need a key object first, e.g. > > > Key formatkey = KeyFactory.createKey(Format.class.getSimpleName(), > > formatId); > > forma = (Format) pm.getObjectById(Format.class, formatkey ); > > > On Aug 10, 11:19 am, aprendiz <[email protected]> wrote: > > > > Hello, I have a (owner) one-to-many bidirectional relationship. > > > A product can have multiple formats, but a format can only be > > > associated with a product. > > > > public class Product{ > > > @PrimaryKey > > > @Persistent > > > private Key id; // string, by application > > > ... > > > @Persistent(mappedBy = "product") > > > private List <Format> formats; > > > > } > > > > public class Format{ > > > @PrimaryKey > > > @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY) > > > private Key id; //numeric, autogenerated > > > ... > > > @Persistent > > > private Product producto; > > > > } > > > > Users select a format in a web page (radio button html) and > > > application (servlet) must load the object identified by id. > > > > My code: > > > forma = (Format) pm.getObjectById(Format.class, formatId); // formatId > > > = 985 > > > > but I get: > > > Could not retrieve entity of kind Format with key Format(985) > > > > Datastore Viewer shows a entity with ID/Name column = 985. > > > > How I must load object? What is wrong? > > > Thank you! -- You received this message because you are subscribed to the Google Groups "Google App Engine for Java" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/google-appengine-java?hl=en.
