title: Entity hierarchies in Objectify 4.0
body: <p>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. </p>
  
  <pre><code>class abstract Base {
  ...
  }
  
  class A extends Base {
  ...
  }
  
  class B extends Base {
  ...
  }
  </code></pre>
  
  <p>I would like to run for example queries as follows.</p>
  
  <ul>
  <li><p>To retrieve all entities of type A and B</p>
  
  <pre><code> Base base = this.objectify.load().type(Base.class).list();
  </code></pre></li>
  <li><p>To retrieve all entities of type A</p>
  
  <pre><code> Base base = this.objectify.load().type(A.class).list();
  </code></pre></li>
  <li><p>To retrieve all entities of type B</p>
  
  <pre><code> Base base = this.objectify.load().type(B.class).list();
  </code></pre></li>
  </ul>
  
  <p>Furthermore, we would like to store all such entities as a single type (Base entity) in GAE Datastore.</p>
  
  <p>We tried to use polymorphic hierarchy of related entity classes described here:</p>
  
  <p><a href="https://code.google.com/p/objectify-appengine/wiki/Entities#Polymorphism" rel="nofollow">https://code.google.com/p/objectify-appengine/wiki/Entities#Polymorphism</a></p>
  
  <p>But it seems that this is not capable of handling a situation where there are multiple entity subclasses with a common parent.</p>