title: JPQL and Inheritance
body: <p>Lets supose that I have 3 abstract super classes: <code>SuperA</code>, <code>SuperB</code> and <code>SuperC</code>.
  Lets supose that each of theses super classes had a lot of more specific implementations, and all the superclasses are annotated with <code>@Inheritance(strategy = InheritanceType.JOINED)</code>.</p>
  
  <p>More specific: </p>
  
  <ul>
  <li><code>Aa</code> &lt;- <code>SuperA</code> and has a List of <code>SuperB</code> (the <code>bbs</code> property); </li>
  <li><code>Bb</code> &lt;- <code>SuperB</code> and has a List of <code>SuperC</code> (the <code>ccs</code> property); </li>
  <li><code>Cc</code> &lt;- <code>SuperC</code> and has a <code>foo</code> property. </li>
  </ul>
  
  <p>Then, when I try a query like the following, I got an error saying that it could not find the property <code>foo</code> in the type <code>SuperC</code>. <code>Bb</code> has a list of the abstract type, and I can't change that. So, I do not know how to make the query works.</p>
  
  <pre><code>select a from Aa a left outer join a.bbs b where b.ccs.foo = :foo
  </code></pre>
  
  <p>Any tip will help. Thanks in advance.</p>
  
  <hr>
  
  <p>Edit:</p>
  
  <p>BTW: the exception: </p>
  
  <p><code>org.hibernate.exception.SQLGrammarException: Unknown column 'cc3_1_.foo' in 'where clause'</code> </p>
  
  <hr>
  
  <p>Edit 2:</p>
  
  <p>I look for JPA docs, and found <a href="http://wiki.eclipse.org/EclipseLink/Development/JPA/QueryDownCast" rel="nofollow">something</a> that could work, if I'm not using Hibernate. </p>
  
  <hr>
  
  <p>Edit 3:</p>
  
  <p>I change it to use two SQL's. First, I find the id of the C based on the <code>foo</code> property, then I just do the query comparing with the id.</p>
  
  <p>The problem here, is that I have to do 2 SQL's for every time I want this... but, at least it works.</p>