Objet avec l'id n'était pas de la sous-classe

J'ai une erreur bizarre sur ma demande.

Je suis en train de récupérer une liste d'entité de base de données (MySQL) avec session.createCriteria().list() mais je reçois ce org.hibernate.WrongClassException.

J'ai regardé cette erreur et je sais ce que cela signifie, mais je ne sais pas comment le résoudre sur mon contexte.

J'ai le texte suivant de la base de données de la structure:

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
)

Donc, rapidement expliquer, toutes les tables sont liées par ces id, et dans le dernier niveau, le vtiger_accountscf tableau a 1 vtiger_accountshipads et 1 vtiger_accountbillads. Toutes les tables ont la même PK.

J'ai donc fait mes classes comme ceci (stubs):

@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 {
}

Et voici mon problème. Quand je fais:

getSession().createCriteria(VtigerAccountbillads.class).list();

Je suis l'exception:

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)

Par les limites du projet, je ne suis pas à l'aide de printemps ou rien de semblable pour configurer la mise en veille prolongée et de créer la session.

Est ma cartographie de mal?

all the tables are linked by the these id columns -- donc vous dire que toutes les tables ont la même valeur pour leurs id? Aussi pouvez-vous préciser ce que vous entendez par in the last level, the vtiger_accountscf table has 1 vtiger_accountshipads and 1 vtiger_accountbillads.
Oui, le même id sur les tables. Je voulais dire que le vtiger_accounts est joint à vtiger_accountbillads et vtiger_accountshipads (c'est l'une des adresses du compte donné)

OriginalL'auteur Alberson Melo | 2014-08-27