Is there a way how to define an entity hierarchy that enables to query just particular subclass? Consider situation below. Let's have abstract Base class that defines common properties and concrete subclasses A and B.
class abstract Base {
...
}
class A extends Base {
...
}
class B extends Base {
...
}
I would like to run for example queries as follows.
To retrieve all entities of type A and B
Base base = this.objectify.load().type(Base.class).list();
To retrieve all entities of type A
Base base = this.objectify.load().type(A.class).list();
To retrieve all entities of type B
Base base = this.objectify.load().type(B.class).list();
Furthermore, we would like to store all such entities as a single type (Base entity) in GAE Datastore.
We tried to use polymorphic hierarchy of related entity classes described here:
https://code.google.com/p/objectify-appengine/wiki/Entities#Polymorphism
But it seems that this is not capable of handling a situation where there are multiple entity subclasses with a common parent.
I don't think
Base
can be abstract, but this should work:If you want to be able to query by polymorphic type, you must index the types that you want to query by.