In GoogleEngine (Java), in JDO, how do I retrieve a list of child objects based on the parent id?

I have two value objects, Calendar and Event, which are persistent. A calendar has a property in the event list with a one-to-many relationship. The calendar is the parent of Events, as shown below.

@Persistent
@Element(dependent = "true")
private List<Event> events;

Now I would like to receive a request through a JDO request, Events corresponding to the calendar, based on the key of the Calendar object. I use encodedKey for both classes.

I want to run a query in an Event entity, and not just get the entire Calendar object, because I want to be able to retrieve only a set of events for pagination purposes.

I tried to do this in any way possible, could not figure out how to request the parent key.

Any help would be appreciated.

+3
source share
1 answer

A few notes:

List properties in objects (like yours List<Event> events) are stored as serialized ProtocolBuffer. The problem is this:

  • If this property is indexed, it is limited to 5000 elements.

  • Each time you request a list, the entire list must be deserialized. This is the answer to your question if you can selectively retrieve list items: you cannot.

  • If you have several indexed list properties in an object, this can lead to Exploding Indexes .

If you want to understand the insides of the GAE data warehouse, then this vido is a must: http://www.youtube.com/watch?v=AgaL6NGpkB8

Solutions:

  • Slatkin: ( ) . : Query.setAncestor(Key calendarKey).

    :. " " . .

  • : Event, Calendar, , . == calendarKey`.

+4

Source: https://habr.com/ru/post/1794797/


All Articles