After more test it seems that I can retrieve ancestor's childs for a
Kind but without Kind the query won't work.

On Jun 20, 8:18 pm, Blaise Gervais <[email protected]> wrote:
> I everyone,
>
> I have a class *GAEDaoSupport* who convert *Object* to *Entity* while
> copying properties. I have a JUnit test for this class who check the
> conversion and try to store and retrieve values.
> When I try to store a *List* of *Entity* where the first is the ancestor and
> others are childs I can retrieve all of them by *Key *but a kindless *Query* 
> on
> ancestor *Key* return nothing.. I suppose that I'va missed something but
> don't now what..
>
> Here is my test case and the output...
>
> > GAEDaoSupport support = *new *GAEDaoSupport(RoleEntity.*class*);
> > RoleEntity object = newRelationsEntity();
>
> > DatastoreService ds = DatastoreServiceFactory.getDatastoreService();
> > List<Entity> entities = support.createEntity(object);
> > System.out.println(" -- [1] Storing "+entities.size()+" entities -------"
> > );
> > System.out.println(entities);
> > List<Key> keys = ds.put(entities);
> > System.out.println("\t  \\-> Done. Keys : "+keys);
>
> > *try *{
> > // Pass...
> > Entity stored = ds.get(entities.get(0).getKey());
> >  assertEquals(entities.get(0), stored);
>
>  // Pass...
>
>
>
>
>
>
>
>
>
> > *for *(*final *Entity child : entities.subList(1, entities.size())) {
> >  assertEquals(child, ds.get(child.getKey()));
> > }
>
> >  // Fail !!! , Result is empty
> > System.out.println();
> >  System.out.println(" -- [2] Retrieving entities by ancestor
> > ------------");
> > Query query = new Query()
> >  .setAncestor(entities.get(0).getKey());
> > System.out.println("\t - Query : "+query);
>
> > List<Entity> childs =
> > ds.prepare(query).asList(FetchOptions.Builder.withDefaults());
> >  System.out.println("\t  \\-> Done : "+childs);
> > } *catch *(EntityNotFoundException e) {
> >  fail(e.getMessage());
> > }
>
> Output :
>
>
>
>
>
>
>
>
>
> >  -- [1] Storing 5 entities -------
> > [<Entity [RoleEntity("Role")]:
> > system = true
>
> > , <Entity [RoleEntity("Role")/Authorisations(no-id-yet)]:
> > access = r
>
> > , <Entity [RoleEntity("Role")/Authorisations(no-id-yet)]:
> >  access = w
>
> > , <Entity [RoleEntity("Role")/UserEntity("0")]:
> > enabled = true
> >  username = User0
> > lastLogin = null
> > email = null
> >  expiration = null
> > password = null
>
> > , <Entity [RoleEntity("Role")/UserEntity("1")]:
> >  enabled = true
> > username = User1
> > lastLogin = null
> >  email = null
> > expiration = null
> > password = null
>
> > ]
> >   \-> Done. Keys : [RoleEntity("Role"),
> > RoleEntity("Role")/Authorisations(1), RoleEntity("Role")/Authorisations(2),
> > RoleEntity("Role")/UserEntity("0"), RoleEntity("Role")/UserEntity("1")]
>
>  -- [2] Retrieving entities by ancestor ------------
>
> >  - Query : SELECT * WHERE __ancestor__ is RoleEntity("Role")
> >   \-> Done : []
>
> My test case use a simple *LocalServiceTestHelper *, like described into the
> gae documentation :
>
>
>
>
>
>
>
> > *private final* LocalServiceTestHelper helper =
> >         *new *LocalServiceTestHelper(*new *
> > LocalDatastoreServiceTestConfig());

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine" 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?hl=en.

Reply via email to