title: How to cast a referenced entity in HQL to its sub-class
body: <p>Suppose there are following entities (JPA annotations are not written):</p>
  
  <pre><code>class Questionnaire {
      ...
  }
  
  class Policy {
      private Questionnaire questionnaire;
      ...
  }
  
  class LifeQuestionnaire extends Questionnaire {
      private String someField;
  }
  
  class LifePolicy extends Policy {  
      ...
  }
  </code></pre>
  
  <p>Well as it seems a Policy references a Questionnaire, but a <code>LifePolicy</code> references a <code>LifeQuestionnaire</code> (this restriction is always true).</p>
  
  <p>Is there any way I can write a query like this:</p>
  
  <pre><code>from LifePolicy lplc
  where ((LifeQuestionnaire) lplc.questionnaire).someField = :fieldValue
  </code></pre>
  
  <p>As you can see, I want to have some kind of casting in the HQL query, because <code>someField</code> is only available in <code>LifeQuestionnaire</code>.</p>