Owned relationships uses entity groups behind-the-scenes:

http://code.google.com/appengine/docs/python/datastore/keysandentitygroups.html#Entity_Groups_Ancestors_and_Paths

An entity group is basically a hierarchy of entities, with one entity as the
root and all other entities below this root. Entity groups can be
arbitrarily deep, so you can have entities with a parent, grandparent,
great-grandparent, and so-on. Owned relationships are maintained by
embedding the parent's key in the child's key -- this is why you can't
change the relationship between parent and child after storing the entities.


Because parent keys are embedded in the child entities, it's possible to
execute an "ancestor" query where you retrieve all entities above a given
entity in the hierarchy. This is pretty straightforward using the low-level
datastore API, but you can do this in JDO as well -- see the last post in
this thread:

http://groups.google.com/group/google-appengine-java/browse_thread/thread/97ba3209ec6a65de

- Jason

On Thu, Sep 3, 2009 at 7:40 PM, Nicholas Albion <[email protected]> wrote:

>
> Could somebody please provide an example of how to query for the one-
> to-many relationship examples in the documentation?
>
> What I want to do is something like the following:
>
> String employeeId = "1234";
> query = pm.newQuery(ContactInfo.class);
> query.setFilter("employee == employeeParam");
> query.declareParameters("String employeeParam");
> List<ContactInfo> employeeContacts = (List<ContactInfo>) query.execute
> ( employeeId );
>
> Should this work?  Or do I need to use an unowned one-to-many,
> replacing "private Employee employee;" with "private Key employeeId;"
> and then something like:
>
> Key employeeId = KeyFactory.createKey(Employee.class.getSimpleName(),
> "1234");
> query = pm.newQuery(ContactInfo.class);
> query.setFilter("employeeId == employeeParam");
> query.declareParameters("Key employeeParam");
> List<ContactInfo> employeeContacts = (List<ContactInfo>) query.execute
> ( employeeId );
>
> (I'm a bit confused by the difference between owned and unowned
> relationships)
> >
>

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to