title: Criteria API: filter by class type
body: <p>I'm relativley new to relational databases and I have some problems concerning the creation of queries. First I want to explain the situation shortly. I have several entity classes. All of them extend <code>AbstractEntity</code> or <code>EntityProperty</code>. So entities can have properties and properties have owning entities, so there is a bidirectional relation.<br>
  Now let's say <code>ConcreteEntity</code> extends <code>AbstractEntity</code> and I want to create queries like this: Get all entities of type <code>ConcreteEntity</code> which has at least on property with a name contained in the given list <code>propertyNames</code>. Until now I have the following working criteria query:</p>
  
  <pre><code>CriteriaQuery&lt;AbstractEntity&gt; cq = cb.createQuery(AbstractEntity.class);
  Root&lt;EntityProperty&gt; property = cq.from(EntityProperty.class);
  Join&lt;EntityProperty, AbstractEntity&gt; entity = property.join(EntityProperty_.owningEntities);
  cq.where(property.get(EntityProperty_.name).in((Object[]) propertyNames));
  cq.select(entity);
  </code></pre>
  
  <p>But now I want only those entities of type <code>ConcreteEntity</code>. How could I achieve this?
  In JPQL I wrote "SELECT entity FROM EntityProperty property JOIN property.owningEntities entity" and here I also have no idea how to write it in the way that only a specific type is returned...  </p>
  
  <p>Thanks for answers in advance!</p>
  
  <p>EDIT: moved the second question to <a href="https://stackoverflow.com/questions/26237579/criteria-query-indistinct-result-lists">criteria query: indistinct result lists</a> and removed distinct in the code (that didn't work)</p>