java - 注释异常 :mappedBy reference an unknown target entity property

标签 java

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

 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;
    }


}

最佳答案

据我所知,您正在使用mappedBy 来列名称而不是本地变量名称

@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") 

在同一个表中两次

关于java - 注释异常 :mappedBy reference an unknown target entity property,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22922327/

相关文章:

java - Spring Tool Suite 入门指南不起作用

java - 设置 Jlabel 以响应 Jbutton,但是当我单击按钮时没有任何响应

java - 使用 Java 远程连接 SafeNet HSM

基于像素模式识别的自动化Java框架

java - 在Kibana中不可见的字段

java - 无法使用 java 运行 First Kaa 应用程序

Java with GSON - 仅将值反序列化为 JSON 字符串的 ArrayList

java - ByteArrayOutputStream.toByteArray() 还是从流中读取?

java - 在模块路径上使用 OpenJFX 11 JMODS 在 JDK 11 上运行 javafx 示例

java - 在 Web 应用程序 Maven 中包含 jar 文件