Hello everyone. I'm having some issue querying the root entity for its 
child entities. Here is a sample of my code

@Test
  public void inviteUserToEvent() throws EntityNotFoundException {

    Person host = new Person("John");
    Person guest = new Person("Adam");

    Entity firstEvent = new Entity("Event", host.getName());
    firstEvent.setProperty("description", "Party tonight");
    firstEvent.setProperty("location", "New York");

    Entity firstInvitation = new Entity("Event", guest.getName(), 
firstEvent.getKey());
    firstInvitation.setProperty("username", guest.getName());
    firstInvitation.setProperty("attending", true);

    Entity secondEvent = new Entity("Event", host.getName());
    secondEvent.setProperty("description", "Going for a walk");
    secondEvent.setProperty("location", "California");

    Entity secondInvitation = new Entity("Event", guest.getName(), 
secondEvent.getKey());
    secondInvitation.setProperty("username", guest.getName());
    secondInvitation.setProperty("attending", false);

    datastore.put(firstEvent);
    datastore.put(secondEvent);
    datastore.put(firstInvitation);
    datastore.put(secondInvitation);

    Query query = new Query("Event");
    query.setFilter(new Query.FilterPredicate("username", 
Query.FilterOperator.EQUAL, guest.getName()));

    List<Entity> entityList = 
datastore.prepare(query).asList(FetchOptions.Builder.withDefaults());

    for (Entity entity : entityList) {
      System.out.println("Key: " + entity.getKey().toString());
      System.out.println("Guest: " + entity.getProperty("username"));
      System.out.println("Attending: " + entity.getProperty("attending"));
      System.out.println("Location: " + 
datastore.get(entity.getParent()).getProperty("location"));
      System.out.println("Description: " + 
datastore.get(entity.getParent()).getProperty("description"));
    }
  }


  class Person {

    private String username;

    public Person(String username) {
      this.username = username;
    }

    public String getName() {
      return username;
    }
  }

And I can only get on of the invitations depending on whether or not I save 
the first or the second one.
I can't get both of them. I think that the problem is in the keys of the 
child entities.
I tried to make the key of the child entities like this without specifying 
the guest's username.

Entity firstInvitation = new Entity("Event", firstEvent.getKey());

But the result was the same.


-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/google-appengine/-/31Ne6uAy33AJ.
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?hl=en.

Reply via email to