title: Hibernate 4: HQL and Inheritance - fetching collections and javassist
body: <p>I'm having this scenario: parent class Person, children classes: Individual and Enterprise. I'm mapping this classes with joined-subclass strategy like this:</p>
  
  <pre><code>&lt;hibernate-mapping&gt;
    &lt;class catalog="test" name="test.Person" table="Persons"&gt;
      &lt;id name="id" type="int"&gt;
        &lt;column name="IdPerson"/&gt;
        &lt;generator class="increment"/&gt;
      &lt;/id&gt;
  
      &lt;set inverse="true" name="addresses"&gt;
        &lt;key&gt;
          &lt;column name="IdPerson" not-null="true"/&gt;
        &lt;/key&gt;
        &lt;one-to-many class="test.Address"/&gt;
      &lt;/set&gt;
  
      &lt;set inverse="true" name="phones"&gt;
        &lt;key&gt;
          &lt;column name="IdPerson" not-null="true"/&gt;
        &lt;/key&gt;
        &lt;one-to-many class="test.Phone"/&gt;
      &lt;/set&gt;
  
      &lt;joined-subclass name="test.Individual" table="Individuals"&gt;
        &lt;key column="IdPerson"/&gt;
  
        &lt;property name="nameIndividual" type="string"&gt;
          &lt;column length="30" name="Name" not-null="true"/&gt;
        &lt;/property&gt;
      ...
      &lt;/joined-subclass&gt;
  
      &lt;joined-subclass name="test.Enterprise" table="Enterprises"&gt;
        &lt;key column="IdPerson"/&gt;
  
        &lt;property name="nameEnterprise" type="string"&gt;
          &lt;column length="30" name="Name" not-null="true"/&gt;
        &lt;/property&gt;
      ...
      &lt;/joined-subclass&gt;
  
    &lt;/class&gt;
  
    &lt;class catalog="test" name="test.Address" table="Addresses"&gt;
  
      &lt;composite-id class="test.AddressId" name="id"&gt;
        &lt;key-many-to-one name="person" class="test.Person"&gt;
          &lt;column name="IdPerson" not-null="true"/&gt;
        &lt;/key-many-to-one&gt;
        &lt;key-property name="id" type="int"&gt;
          &lt;column name="IdAddress"/&gt;
        &lt;/key-property&gt;
      &lt;/composite-id&gt;
  
      &lt;many-to-one name="person" class="test.Person" fetch="select" insert="false" update="false"&gt;
        &lt;column name="IdPerson" not-null="true"/&gt;
      &lt;/many-to-one&gt;
      ...    
    &lt;/class&gt;
  
    &lt;class catalog="test" name="test.Phone" table="Phones"&gt;
  
      &lt;composite-id class="test.PhoneId" name="id"&gt;
        &lt;key-many-to-one name="person" class="test.Person"&gt;
          &lt;column name="IdPerson" not-null="true"/&gt;
        &lt;/key-many-to-one&gt;
        &lt;key-property name="id" type="int"&gt;
          &lt;column name="IdPhone"/&gt;
        &lt;/key-property&gt;
      &lt;/composite-id&gt;
  
      &lt;many-to-one name="person" class="test.Person" fetch="select" insert="false" update="false"&gt;
        &lt;column name="IdPerson" not-null="true"/&gt;
      &lt;/many-to-one&gt;
      ...
    &lt;/class&gt;
  
  &lt;/hibernate-mapping&gt;
  </code></pre>
  
  <p>When I use this simple HQL to load a list of Persons:</p>
  
  <pre><code>List result = session.createQuery("from Person as en").list();
  </code></pre>
  
  <p>hibernate resolves the polymorphism ok, and I get a list of Individuals and Enterprises objects.</p>
  
  <p>But when I include the Addresses and Phones:</p>
  
  <pre><code>List result = session.createQuery("from Person as en left join fetch en.addresses left join fetch en.phones").list();
  </code></pre>
  
  <p>hibernate returns a list of Person_$$_javassist_5 objects with no access to the specific properties of Indivual and Enterprise classes.</p>
  
  <p>Is this the expected behaviour? How could I solve this?</p>
  
  <p>Thanks in advance.</p>
  
  <p><strong>EDITED:</strong></p>
  
  <p>I have included the Address and Phone classes mapping, its id's are composite and it seems to be the reason for the <em>javassist</em> proxy generated by hibernate, but why the proxy doesn't resolve the polymorphism correctly? even when hibernate gets all data from database.</p>
  
  <p>My JSF page throws an javax.el.PropertyNotFoundException error: The class 'test.Person_$$_javassist_5' does not have the property 'nameIndividual'.</p>