gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 13:10:21 28 4
gpt4 key购买 nike

我在带注释的对象中设置一对多关系时遇到问题。我有以下内容:我的应用程序有简单的映射,就像一个阶段可以有很多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/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com