title: Object with id was not of the specified subclass
body: <p>I'm getting a weird error on my application.<br>
  I'm trying to retrieve an list of entity from database (MySQL) with <code>session.createCriteria().list()</code> but I'm getting this <code>org.hibernate.WrongClassException</code>.</p>
  
  <p>I have looked up this error and I know what it means, but I don't know how to solve it on my context.</p>
  
  <p>I have the following database structure:</p>
  
  <pre class="lang-sql prettyprint-override"><code>CREATE TABLE vtiger_crmentity (
  `crmid` int(19) NOT NULL
  )
  
  CREATE TABLE vtiger_account (
      `accountid` int(19) NOT NULL DEFAULT 0
  )
  
  CREATE TABLE vtiger_accountscf (
      `accountid` int(19) NOT NULL DEFAULT 0
  )
  
  CREATE TABLE vtiger_accoutshipads (
  `accountaddressid` int(19) NOT NULL DEFAULT 0
  )
  
  CREATE TABLE vtiger_accountbillads (
      `accountaddressid` int(19) NOT NULL DEFAULT 0
  )
  </code></pre>
  
  <p>So, quickly explaining, all the tables are linked by the these id columns, and in the last level, the <code>vtiger_accountscf</code> table has 1 <code>vtiger_accountshipads</code> and 1 <code>vtiger_accountbillads</code>. All the tables have the same PK.<br>
  So I made my classes like this (stubs):</p>
  
  <pre class="lang-java prettyprint-override"><code>@Entity
  @Inheritance(strategy = InheritanceType.JOINED)
  @Table(name = "vtiger_crmentity")
  public class VtigerCrmentity {
    @Id
    @Basic(optional = false)
    @Column(name = "crmid", nullable = false)
    public Integer getId() {
      return this.id;
  
    }
  }
  
  
  @Entity
  @PrimaryKeyJoinColumn(name = "accountid")
  @Inheritance(strategy = InheritanceType.JOINED)
  @Table(name = "vtiger_account")
  public class VtigerAccount extends VtigerCrmentity {
  
  }
  
  @Entity
  @PrimaryKeyJoinColumn(name = "accountid")
  @Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
  @Table(name = "vtiger_accountscf")
  public class VtigerAccountscf extends VtigerAccount {
  }
  
  @Entity
  @PrimaryKeyJoinColumn(name = "accountaddressid")
  @Table(name = "vtiger_accountbillads")
  public class VtigerAccountbillads extends VtigerAccountscf {
  }
  
  @Entity
  @PrimaryKeyJoinColumn(name = "accountaddressid")
  @Table(name = "vtiger_accountshipads")
  public class VtigerAccountshipads extends VtigerAccountscf {
  }
  </code></pre>
  
  <p>And here's my problem. When I do:</p>
  
  <pre class="lang-java prettyprint-override"><code>getSession().createCriteria(VtigerAccountbillads.class).list();
  </code></pre>
  
  <p>I'm getting the exception:</p>
  
  <pre><code>org.hibernate.WrongClassException: Object with id: 11952 was not of the specified subclass: VtigerAccountbillads (loaded object was of wrong class class VtigerAccountshipads)
      at org.hibernate.loader.Loader.instanceAlreadyLoaded(Loader.java:1391)
      at org.hibernate.loader.Loader.getRow(Loader.java:1344)
      at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:611)
      at org.hibernate.loader.Loader.doQuery(Loader.java:829)
      at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:274)
      at org.hibernate.loader.Loader.doList(Loader.java:2533)
      at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2276)
      at org.hibernate.loader.Loader.list(Loader.java:2271)
      at org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:119)
      at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1716)
      at org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:347)
  </code></pre>
  
  <p>By project limitations, I'm not using spring or nothing similar to configure the Hibernate and create the session.</p>
  
  <p>Is my mapping wrong?</p>