title: Using Hibernate Criteria API, how to query for a subproperty of a property that exists only for certain property types
body: <p>Consider classes <code>Account</code>, <code>RealAccount</code>, <code>VirtualAccount</code>, and <code>Operation</code> such that:</p>
  
  <pre><code>class Account { }
  class RealAccount extends Account { String name; }
  class VirtualAccount extends Account { }
  class Operation { Account account; }
  </code></pre>
  
  <p>This means that:</p>
  
  <ol>
  <li>Only <code>RealAccount</code> has a field called <code>name</code>.</li>
  <li><code>Operation</code>'s account can be <code>RealAccount</code> or <code>VirtualAccount</code>.</li>
  </ol>
  
  <p>I want to query for all <code>Operation</code>s that belong to a <code>RealAccount</code> with a specific name:</p>
  
  <pre><code>session.createCriteria(Operation.class)
     .createAlias("account", "_account")
     .add(Restrictions.eq("_account.name", "Alice"))
     .list();
  </code></pre>
  
  <p>This fails.</p>
  
  <p>My question: Using the <strong>"old" Hibernate Criteria API</strong>, how can I query for the <strong>account name</strong> that exists only when the <code>Operation</code>'s account is a <code>RealAccount</code>? Maybe something envolving <code>DetachedCriteria</code> and <code>Subqueries</code>...</p>