外键引用的列数错误 [英] A Foreign key refering has wrong number of columns

查看:88
本文介绍了外键引用的列数错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在JPA和ManyToMany关联方面遇到问题.

I got a problem with JPA and ManyToMany association.

我有两个类FOA_PARAM_EMPLOYE和FOA_PARAM_POSITION,以及一个关联表FOA_PARAM_EMPLOYE_POSITION.

I got two class FOA_PARAM_EMPLOYE and FOA_PARAM_POSITION, and an association table FOA_PARAM_EMPLOYE_POSITION.

FoaParamEmploye类:

Class FoaParamEmploye :

@Entity
@Table(name = "FOA_PARAM_EMPLOYE")
@NamedQuery(name = "FoaParamEmploye.findAll", query = "SELECT f FROM FoaParamEmploye f")
public class FoaParamEmploye implements Serializable {
private static final long serialVersionUID = 1L;

@EmbeddedId
private FoaParamEmployePK id;

@Column(name = "ACTEUR_MAJ_OCCUR")
private String acteurMajOccur;

@Column(name = "ADRESSE_EMAIL")
private String adresseEmail;

// bi-directional many-to-many association to FoaParamPosition
@ManyToMany
@JoinTable(
        name = "FOA_PARAM_EMPLOYE_POSITION", 
        joinColumns = { @JoinColumn(name = "ID_EMPLOYE"),
                        @JoinColumn(name = "COD_ENTREP") }, 
        inverseJoinColumns = { @JoinColumn(name = "ID_POSITION")
})
private List<FoaParamPosition> foaParamPositions;

public FoaParamEmployePK getId() {
    return this.id;
}

public void setId(FoaParamEmployePK id) {
    this.id = id;
}

public String getActeurMajOccur() {
    return this.acteurMajOccur;
}

public void setActeurMajOccur(String acteurMajOccur) {
    this.acteurMajOccur = acteurMajOccur;
}

public String getAdresseEmail() {
    return this.adresseEmail;
}

public void setAdresseEmail(String adresseEmail) {
    this.adresseEmail = adresseEmail;
}

public List<FoaParamPosition> getFoaParamPositions() {
    return foaParamPositions;
}

public void setFoaParamPositions(List<FoaParamPosition> pFoaParamPositions) {
    this.foaParamPositions = pFoaParamPositions;
}
}

FoaParamPosition类:

Class FoaParamPosition :

@Entity
@Table(name="FOA_PARAM_POSITION")
@NamedQuery(name="FoaParamPosition.findAll", query="SELECT f FROM FoaParamPosition f")
public class FoaParamPosition implements Serializable {
private static final long serialVersionUID = 1L;

@EmbeddedId
private FoaParamPositionPK id;

@Column(name="ACTEUR_MAJ_OCCUR")
private String acteurMajOccur;

@Column(name="CD_PROFIL_AFFECTATION")
private String cdProfilAffectation;

// bi-directional many-to-many association to FoaParamEmploye
@ManyToMany
private List<FoaParamEmploye> foaParamEmployes;

public FoaParamPositionPK getId() {
    return this.id;
}

public void setId(FoaParamPositionPK id) {
    this.id = id;
}

public String getActeurMajOccur() {
    return this.acteurMajOccur;
}

public void setActeurMajOccur(String acteurMajOccur) {
    this.acteurMajOccur = acteurMajOccur;
}

public String getCdProfilAffectation() {
    return this.cdProfilAffectation;
}

public void setCdProfilAffectation(String cdProfilAffectation) {
    this.cdProfilAffectation = cdProfilAffectation;
}

public List<FoaParamEmploye> getFoaParamEmployes() {
    return foaParamEmployes;
}

public void setFoaParamEmployes(List<FoaParamEmploye> pFoaParamEmployes) {
    this.foaParamEmployes = pFoaParamEmployes;
}
}

表FOA_PARAM_EMPLOYE_POSITION包含以下列:

Table FOA_PARAM_EMPLOYE_POSITION has this columns :

COD_ENTREP
ID_EMPLOYE
ID_POSITION
XQCIF
ACTEUR_MAJ_OCCUR
DATE_HEURE_MAJ_OCCUR

我遇到了这个异常:

A Foreign key refering com.groupama.middlgan.entities.FoaParamPosition from
com.groupama.middlgan.entities.FoaParamEmploye has the wrong number of column. 
should be 2

如果我在FoaParamEmploye实体的inverseJoinColumns上添加COD_ENTREP,则会出现此异常:

If I add COD_ENTREP on inverseJoinColumns in my FoaParamEmploye entity, I got this exception :

Repeated column in mapping for collection: 
com.groupama.middlgan.entities.FoaParamEmploye.foaParamPositions column: COD_ENTREP

有想法吗?

推荐答案

如果要保留inverseJoinColumn映射,可以执行以下操作,

If you want to keep your inverseJoinColumn mapping you can do as follows,

@ManyToMany
@JoinTable(
    name = "FOA_PARAM_EMPLOYE_POSITION", 
    joinColumns = { @JoinColumn(name = "ID_EMPLOYE"),
                    @JoinColumn(name = "COD_ENTREP") }
,
        inverseJoinColumns = {@JoinColumn(name = "FOAPARAMPOSITION_COD_ENTREP"), @JoinColumn(name = "FOAPARAMPOSITION_ID_POSITION")}
)
private List<FoaParamPosition> foaParamPosition;

@ManyToMany
@JoinTable(
    name = "FOA_PARAM_EMPLOYE_POSITION", 
    joinColumns = { @JoinColumn(name = "ID_POSITION"),
                    @JoinColumn(name = "COD_ENTREP") }
        ,
        inverseJoinColumns = {@JoinColumn(name = "FOAPARAMEMPLOYE_COD_ENTREP"), @JoinColumn(name = "FOAPARAMEMPLOYE_ID_EMPLOYE")}

)
private List<FoaParamEmploye> foaParamEmploye;

映射与您在其他问题中发布的代码对齐 JPA多对多选择

the mappings are aligned with the code you've posted in your other question JPA Many To Many Select

这篇关于外键引用的列数错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆