web-dev-qa-db-fra.com

org.hibernate.MappingException: impossible de trouver la colonne avec le nom logique

salut mes tableaux sont les suivants:

1- medical_company:

  • medical_company_id clé étrangère on account_entity table account_entity_id colonne (pas un pk)
  • colonne1
  • colonne2
  • colonne3

2- account_entity:

  • account_entity_id (pk)
  • colonne1
  • colonne2
  • colonne3

3- personne:

  • id_personne (pk)
  • colonne1
  • colonne2
  • colonne3

4- entreprise_employé:

  • clé étrangère company_id sur medical_company table sur medical_company_id
  • d'employé_id clé étrangère sur personne table sur personne_id
  • colonne1
  • colonne2

ENTITÉS:

1- MedicalCompany:

@SuppressWarnings("serial")
@Entity
@Table(name = "medical_company")
public class MedicalCompany implements Serializable {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id", unique = true, nullable = false)
@Basic(fetch = FetchType.EAGER)
private Long id;

@OneToOne
@Cascade(value = { CascadeType.ALL })
@JoinColumn(name = "medical_company_id", referencedColumnName = "account_entity_id")
private AccountEntity accountEntity;

}

2- AccountEntity:

@SuppressWarnings("serial")
@Entity
@Table(name = "account_entity")
public class AccountEntity implements Serializable {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "account_entity_id", unique = true, nullable = false)
    @Basic(fetch = FetchType.EAGER)
    private Long id;

}

3- Personne:

 @SuppressWarnings("serial")
@Entity
@Table(name = "person")
public class Person implements Serializable {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "person_id", unique = true, nullable = false)
    @Basic(fetch = FetchType.EAGER)
    private Long id;

}

4- EmployeeCompanyId:

@SuppressWarnings("serial")
@Embeddable
public class EmployeeCompanyId implements Serializable {

    @ManyToOne
    private Person person;

    @ManyToOne
    private MedicalCompany medicalCompany;

    @Size(max = 150, message = "{long.value}")
    @Column(name = "title_text", length = 150, nullable = true)
    private String titleText;

    @Column(name = "employee_manager")
    private long employeeManager;


}

5- EmployeeCompany:

@SuppressWarnings("serial")
@Entity
@Table(name = "employee_company")
@AssociationOverrides(value = {
        @AssociationOverride(name = "pk.medicalCompany", joinColumns = @JoinColumn(referencedColumnName = "medical_company_id")),
        @AssociationOverride(name = "pk.person", joinColumns = @JoinColumn(referencedColumnName = "person_id")),
        @AssociationOverride(name = "pk.titleText"),
        @AssociationOverride(name = "pk.employeeManager") })
public class EmployeeCompany implements Serializable {

    @EmbeddedId
    private EmployeeCompanyId pk = new EmployeeCompanyId();

    @Transient
    public void setEmployeeManager(long employeeManager) {
        this.pk.setEmployeeManager(employeeManager);
    }

    public long getEmployeeManager() {
        return pk.getEmployeeManager();
    }

    @Transient
    public void setTitleText(String titleText) {
        this.pk.setTitleText(titleText);
    }

    public String getTitleText() {
        return pk.getTitleText();
    }

    public void setPerson(Person person) {
        this.pk.setPerson(person);
    }

    @Transient
    public Person getPerson() {
        return this.pk.getPerson();
    }

    public void setMedicalCompany(MedicalCompany medicalCompany) {
        this.pk.setMedicalCompany(medicalCompany);
    }

    @Transient
    public MedicalCompany getMedicalCompany() {
        return this.pk.getMedicalCompany();
    }

    public void setPk(EmployeeCompanyId pk) {
        this.pk = pk;
    }

    public EmployeeCompanyId getPk() {
        return pk;
    }

}

lorsque j'essaie d'exécuter l'application, j'obtiens l'erreur suivante:

org.hibernate.MappingException: Unable to find column with logical name: medical_company_id in org.hibernate.mapping.Table(medical_company) and its related supertables and secondary tables
    at org.hibernate.cfg.Ejb3JoinColumn.checkReferencedColumnsType(Ejb3JoinColumn.Java:550)
    at org.hibernate.cfg.BinderHelper.createSyntheticPropertyReference(BinderHelper.Java:126)
    at org.hibernate.cfg.ToOneFkSecondPass.doSecondPass(ToOneFkSecondPass.Java:110)
    at org.hibernate.cfg.AnnotationConfiguration.processFkSecondPassInOrder(AnnotationConfiguration.Java:520)
    at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.Java:380)
    at org.hibernate.cfg.Configuration.buildMappings(Configuration.Java:1206)
    at org.springframework.orm.hibernate3.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.Java:717)
    at org.springframework.orm.hibernate3.AbstractSessionFactoryBean.afterPropertiesSet(AbstractSessionFactoryBean.Java:211)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.Java:1477)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.Java:1417)

veuillez indiquer pourquoi j'obtiens cette erreur et comment la résoudre.

16
Mahmoud Saleh

Cette erreur vous indique qu'il n'y a pas de colonne sur la table medical_company appelée medical_company_id. La colonne sur medical_company s'appelle simplement id.

6
Alex Barnes

Je supprimerais l'attribut referencedColumnName dans MedicalCompany car vous nommez le champ de clé primaire de AccountEntity. Je pense que cela n'est nécessaire que si vous faites référence à un champ de clé non primaire.

@JoinColumn(name = "medical_company_id", referencedColumnName = "account_entity_id")
23
BikeHikeJuno