AnnotationException:mappedBy引用未知的目标实体属性

时间:2014-04-07 20:22:58

标签: java

我在注释对象中设置一对多关系时遇到问题。 我有以下内容: 我的应用程序具有简单的映射,就像一个阶段可以有许多环节(任务)。但任务只能属于单一阶段。这是我认为代码应该是什么。 这是任务类     在这里输入代码

 package com.gestion.projet.entities;
 import java.io.Serializable;
 import java.util.Collection;
 import java.util.Date;
 import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
@Entity
@Table(name="Tache")
public class Tache implements Serializable{
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
private Long idTache;
private String nomTache;
private String statusTache;
private Date dateDebut;
private Date dateFin;
@ManyToOne
@JoinColumn(name="idPhase")
private Tache tacheParente;
private Long predecesseur;
private Long durre;
private String commentaire;
private String type ;
private boolean confidentialité;
@ManyToOne
@JoinColumn(name="idPhase")
private Phase phases;
@OneToMany(mappedBy="idTache")
private Collection<MembreTache> membreTaches;

public Tache(String nomTache, String statusTache, Date dateDebut,
        Date dateFin, Tache tacheParente, Long predecesseur, Long durre,
        String commentaire, String type, boolean confidentialité) {
    super();
    this.nomTache = nomTache;
    this.statusTache = statusTache;
    this.dateDebut = dateDebut;
    this.dateFin = dateFin;
    this.tacheParente = tacheParente;
    this.predecesseur = predecesseur;
    this.durre = durre;
    this.commentaire = commentaire;
    this.type = type;
    this.confidentialité = confidentialité;
}

public String getNomTache() {
    return nomTache;
}

public void setNomTache(String nomTache) {
    this.nomTache = nomTache;
}

public String getStatusTache() {
    return statusTache;
}

public void setStatusTache(String statusTache) {
    this.statusTache = statusTache;
}

public Date getDateDebut() {
    return dateDebut;
}

public void setDateDebut(Date dateDebut) {
    this.dateDebut = dateDebut;
}

public Date getDateFin() {
    return dateFin;
}

public void setDateFin(Date dateFin) {
    this.dateFin = dateFin;
}

public Tache getTacheParente() {
    return tacheParente;
}

public void setTacheParente(Tache tacheParente) {
    this.tacheParente = tacheParente;
}

public Long getPredecesseur() {
    return predecesseur;
}

public void setPredecesseur(Long predecesseur) {
    this.predecesseur = predecesseur;
}

public Tache() {
    super();
    // TODO Auto-generated constructor stub
}

public Long getDurre() {
    return durre;
}

public void setDurre(Long durre) {
    this.durre = durre;
}

public String getCommentaire() {
    return commentaire;
}

public void setCommentaire(String commentaire) {
    this.commentaire = commentaire;
}

public String getType() {
    return type;
}

public void setType(String type) {
    this.type = type;
}

public boolean isConfidentialité() {
    return confidentialité;
}

public void setConfidentialité(boolean confidentialité) {
    this.confidentialité = confidentialité;
}

} 这是阶段类:

package com.gestion.projet.entities;

import java.io.Serializable;
import java.util.Collection;
import java.util.Date;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
@Entity
@Table(name="Phase")
public class Phase implements Serializable {
    @Id
    @GeneratedValue(strategy=GenerationType.IDENTITY)
    private Long idPhase;
    private String typePhase;
    private String desc;
    private Date dateDebut;
    @OneToMany(mappedBy="idPhase")
    private Collection<Tache> taches;
    private Date dateFin;
    @ManyToOne
    @JoinColumn(name="idProjet")
    private Projet projet;
    /*------*/
    public String getTypePhase() {
        return typePhase;
    }
    public void setTypePhase(String typePhase) {
        this.typePhase = typePhase;
    }
    public String getDesc() {
        return desc;
    }
    public void setDesc(String desc) {
        this.desc = desc;
    }
    public Date getDateDebut() {
        return dateDebut;
    }
    public void setDateDebut(Date dateDebut) {
        this.dateDebut = dateDebut;
    }
    public Date getDateFin() {
        return dateFin;
    }
    public void setDateFin(Date dateFin) {
        this.dateFin = dateFin;
    }
    public Phase() {
        super();
        // TODO Auto-generated constructor stub
    }
    public Phase(String typePhase, String desc, Date dateDebut,
            Date dateFin) {
        super();

        this.typePhase = typePhase;
        this.desc = desc;
        this.dateDebut = dateDebut;
        this.dateFin = dateFin;
    }


}

1 个答案:

答案 0 :(得分:1)

正如我所见,您正在使用mappedBy到Collumn名称而不是本地变量名称

@ManyToOne
@JoinColumn(name="idPhase")
private Phase phases; (why plural ?)

应该通过

进行映射
@OneToMany(mappedBy="phases")
private Collection<Tache> taches;

@OneToMany(mappedBy="idPhase")
private Collection<Tache> taches;

还有:

@JoinColumn(name="idPhase") 

在同一张桌子中两次