title: HQL to access the subclass object of @manytoOne fields
body: <p>I have scenario in which below is the superclass:-</p>
  
  <pre><code>abstract class  Container
  {
      Long id;
      FieldParent parent;
  }
  
  class SubContainer extends Container
  {
      Long extid;
  }
  
  abstract class FieldParent
  {
      Long fid;
      String name;
  }
  
  class SubField  extends FieldParent
  {
      String typeOfSub;
  }
  </code></pre>
  
  <p>I am using Table per subclass strategy using a discriminator
  Below is hbm mapping of Container:-</p>
  
  <pre><code>&lt;class name="Container" table="Container"&gt;
      &lt;id name="id" type="long" column="ID"&gt;
          &lt;generator class="native"/&gt;
      &lt;/id&gt;
       &lt;many-to-one name="parent"
                       class="FieldParent"
                       cascade="none"
                       column="FieldParentID"/&gt;
      &lt;discriminator column="TYPE"/&gt;
      ....
      &lt;subclass name="SubContainer"
                    discriminator-value="S"
                    lazy="true"&gt;
            &lt;property name="extid"  type="long"  column="extid" not-null="true"/&gt;
      &lt;/subclass&gt;
  &lt;/class&gt;
  </code></pre>
  
  <p>Below is hbm mapping of FieldParent:-</p>
  
  <pre><code>   &lt;class name="FieldParent" table="FieldParent"&gt;
          &lt;id name="fid" type="long" column="FID"&gt;
              &lt;generator class="native"/&gt;
          &lt;/id&gt;
          &lt;property name="name"  type="java.lang.String"  column="name" not-null="true"/&gt;
          &lt;discriminator column="TYPE_Parent"/&gt;
          ....
          &lt;subclass name="SubField"
                        discriminator-value="F"
                        lazy="true"&gt;
              &lt;property name="typeOfSub"  type="java.lang.String"  column="typeOfSub" not-null="true"/&gt;
          &lt;/subclass&gt;
      &lt;/class&gt;
  </code></pre>
  
  <p>Now I have the object of SubContainer and I am query based on 'typeOfSub' value.
  I tried using below query </p>
  
  <pre><code>getHibernateTemplate().find(
          "from " + SubContainer.class.getName()
                  + " subContainer where subContainer.extid = ? and subContainer.parent.typeOfSub=? ",
          new Object[]{new Long(id), "sampeTypeoFSub"});
  </code></pre>
  
  <p>but faced 'org.hibernate.PropertyAccessException: IllegalArgumentException occurred '.<br/>
  I understand I cant be just assume that it will be SubField object so cant access the fields but I need to figuure out the way for. I am not sure if we can cast in HQL?<br/>
  I tried searching for the resolution but dint find any similar question.</p>
  
  <p>Below is the stacktrace :</p>
  
  <blockquote>
    <p>java.sql.SQLSyntaxErrorException: ORA-00904: "FieldParent_3_"."typeOfSub": invalid identifier
    at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:445) [ojdbc6.jar:11.2.0.3.0]
    at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:396) [ojdbc6.jar:11.2.0.3.0]
    at oracle.jdbc.driver.T4C8Oall.processError(T4C8Oall.java:879) [ojdbc6.jar:11.2.0.3.0]
    at oracle.jdbc.driver.T4CTTIfun.receive(T4CTTIfun.java:450) [ojdbc6.jar:11.2.0.3.0]
    at oracle.jdbc.driver.T4CTTIfun.doRPC(T4CTTIfun.java:192) [ojdbc6.jar:11.2.0.3.0]
    at oracle.jdbc.driver.T4C8Oall.doOALL(T4C8Oall.java:531) [ojdbc6.jar:11.2.0.3.0]
    at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:207) [ojdbc6.jar:11.2.0.3.0]
    at oracle.jdbc.driver.T4CPreparedStatement.executeForDescribe(T4CPreparedStatement.java:884) [ojdbc6.jar:11.2.0.3.0]
    at oracle.jdbc.driver.OracleStatement.executeMaybeDescribe(OracleStatement.java:1167) [ojdbc6.jar:11.2.0.3.0]
    at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1281) [ojdbc6.jar:11.2.0.3.0]
    at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3584) [ojdbc6.jar:11.2.0.3.0]
    at oracle.jdbc.driver.OraclePreparedStatement.executeQuery(OraclePreparedStatement.java:3628) [ojdbc6.jar:11.2.0.3.0]
    at oracle.jdbc.driver.OraclePreparedStatementWrapper.executeQuery(OraclePreparedStatementWrapper.java:1493) [ojdbc6.jar:11.2.0.3.0]
    at org.jboss.resource.adapter.jdbc.WrappedPreparedStatement.executeQuery(WrappedPreparedStatement.java:342) [:6.0.0.Final]</p>
  </blockquote>
  
  <p>Updated stack trace for exception.Also just FYI, FieldParent has 3 subclasses one of which is SubField . </p>
  
  <blockquote>
    <p>java.sql.SQLSyntaxErrorException: ORA-00904: "FieldParent1_3_"."typeOfSub": invalid identifier</p>
  </blockquote>
  
  <pre><code>    at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:445) [ojdbc6.jar:11.2.0.3.0]
      at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:396) [ojdbc6.jar:11.2.0.3.0]
      at oracle.jdbc.driver.T4C8Oall.processError(T4C8Oall.java:879) [ojdbc6.jar:11.2.0.3.0]
      at oracle.jdbc.driver.T4CTTIfun.receive(T4CTTIfun.java:450) [ojdbc6.jar:11.2.0.3.0]
      at oracle.jdbc.driver.T4CTTIfun.doRPC(T4CTTIfun.java:192) [ojdbc6.jar:11.2.0.3.0]
      at oracle.jdbc.driver.T4C8Oall.doOALL(T4C8Oall.java:531) [ojdbc6.jar:11.2.0.3.0]
      at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:207) [ojdbc6.jar:11.2.0.3.0]
      at oracle.jdbc.driver.T4CPreparedStatement.executeForDescribe(T4CPreparedStatement.java:884) [ojdbc6.jar:11.2.0.3.0]
      at oracle.jdbc.driver.OracleStatement.executeMaybeDescribe(OracleStatement.java:1167) [ojdbc6.jar:11.2.0.3.0]
      at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1281) [ojdbc6.jar:11.2.0.3.0]
      at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3584) [ojdbc6.jar:11.2.0.3.0]
      at oracle.jdbc.driver.OraclePreparedStatement.executeQuery(OraclePreparedStatement.java:3628) [ojdbc6.jar:11.2.0.3.0]
      at oracle.jdbc.driver.OraclePreparedStatementWrapper.executeQuery(OraclePreparedStatementWrapper.java:1493) [ojdbc6.jar:11.2.0.3.0]
      at org.jboss.resource.adapter.jdbc.WrappedPreparedStatement.executeQuery(WrappedPreparedStatement.java:342) [:6.0.0.Final]
      at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:208) [:3.6.10.Final]
      at org.hibernate.loader.Loader.getResultSet(Loader.java:1953) [:3.6.10.Final]
  </code></pre>