Reputation: 1121
We have a parent - child entity model which contains the following:
@PersistenceCapable(detachable = "true")
public class Area implements Serializable {
@PrimaryKey
private String name;
@Persistent(mappedBy = "area")
@Element(dependent = "true")
private List<Category> categories;
}
@PersistenceCapable(detachable = "true")
public class Category implements Serializable {
@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
@Extension(vendorName="datanucleus", key="gae.encoded-pk", value="true")
private String key;
@Persistent
private Area area;
}
When we retrieve all the Areas along with their Categories, can we sorts the results by category name?
I saw that JDO Query has a setOrdering method, although it seems to be applied on properties of the entity you query on and not its child entity.
We currently conduct the sort using TreeMap although it will be much better to use JDO/GSQL for that.
Upvotes: 0
Views: 108
Reputation: 2237
No - App Engine does not support join queries, so you cannot query a parent entity using an attribute of a child entity. (https://developers.google.com/appengine/docs/java/datastore/jdo/relationships#Owned_One_to_Many_Relationships).
You can query a property of an embedded class, so you might consider whether that would suit your use case.
If your categories have unique names, you could consider a different design where you use the category names as the Category entity key name strings. Then, you can store a list of category name strings in each Area entity (as an indexed, multivalued property).
With such a design, you would be managing the parent-child relationship via a list of child key names rather than via JDO's support for owned relationships.
Upvotes: 2