当前位置: 首页 > 知识库问答 >
问题:

Hibernate mappedBy引用未知目标实体

孔深
2023-03-14

我有几个从db动态创建的实体类,但是当我用关系注释它们时,我有以下错误

mappedBy reference an unknown target entity property:         coma.entity.impl.CompetenceCriteriaEntityImpl.competence in coma.entity.impl.CompetenceEntityImpl.competenceCriteriaEntityImpl] with root cause

组织。冬眠AnnotationException:mappedBy引用未知的目标实体属性:coma。实体impl。能力标准实施。昏迷中的能力。实体impl。胜任力impl。能力标准执行

我的实体类如下

package coma.entity.impl;
import java.io.Serializable;
import java.util.Set;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import coma.entity.CompetenceEntity;
import coma.exception.InvalidIDException;


@Entity
@Table(name = "competence")
public class CompetenceEntityImpl implements CompetenceEntity, Serializable {
@OneToMany(fetch = FetchType.EAGER, mappedBy = "competence", targetEntity = JobProfileCompetenceEntityImpl.class)
public Set<JobProfileCompetenceEntityImpl> jobProfileCompetenceEntityImpl;

@OneToMany(fetch = FetchType.EAGER, mappedBy = "competence",targetEntity = CompetenceCriteriaEntityImpl.class)
public Set<CompetenceCriteriaEntityImpl> competenceCriteriaEntityImpl;
/**
 * 
 */



/**
 * Identifier of competence
 */
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id_competence")
private int idCompetence;



public Set<JobProfileCompetenceEntityImpl> getJobProfileCompetenceEntityImpl() {
    return jobProfileCompetenceEntityImpl;
}

public void setJobProfileCompetenceEntityImpl(Set<JobProfileCompetenceEntityImpl> jobProfileCompetenceEntityImpl) {
    this.jobProfileCompetenceEntityImpl = jobProfileCompetenceEntityImpl;
}

public Set<CompetenceCriteriaEntityImpl> getCompetenceCriteriaEntityImpl() {
    return competenceCriteriaEntityImpl;
}

public void setCompetenceCriteriaEntityImpl(Set<CompetenceCriteriaEntityImpl> competenceCriteriaEntityImpl) {
    this.competenceCriteriaEntityImpl = competenceCriteriaEntityImpl;
}

public void setIdCompetence(int idCompetence) {
    this.idCompetence = idCompetence;
}

/**
 * Name of competence
 */
@Column(name = "name_competence")
private String nameCompetence;

/**
 * Identifier category competence
 */
@Column(name = "id_category_competence_enum")
private int idCategoryCompetenceEnum;

/**
 * Constructor without parameters
 */
public CompetenceEntityImpl() {

}

/**
 * Constructor with parameters
 * 
 * @param idCompetence
 * @param nameCompetence
 * @param idCategoryCompetenceEnum
 */
public CompetenceEntityImpl(int idCompetence, String nameCompetence, int idCategoryCompetenceEnum) {
    this.idCompetence = idCompetence;
    this.nameCompetence = nameCompetence;
    this.idCategoryCompetenceEnum = idCategoryCompetenceEnum;
}

/**
 * Return identifier of current competence
 * 
 * @return idCompetence
 */
@Override
public int getIdCompetence() {
    return idCompetence;
}

/**
 * Return name of current competence
 * 
 * @return nameCompetence
 */
@Override
public String getNameCompetence() {
    return nameCompetence;
}

/**
 * Set name of current competence
 * 
 * @param nameCompetence
 */
@Override
public void setNameCompetence(String nameCompetence) {
    this.nameCompetence = nameCompetence;
}

/**
 * Return identifier category competence
 * 
 * @return idCategoryCompetence
 */
@Override
public int getIdCategoryCompetenceEnum() {
    return idCategoryCompetenceEnum;
}

/**
 * Set identifier category competence
 * 
 * @param idCategoryCompetenceEnum
 */
@Override
public void setIdCategoryCompetenceEnum(int idCategoryCompetenceEnum) throws InvalidIDException {
    if (idCategoryCompetenceEnum < 0) {
        throw new InvalidIDException("The idCategoryCompetenceEnum must be greater than 0");
    } else {
        this.idCategoryCompetenceEnum = idCategoryCompetenceEnum;
    }

}

@Override
public int hashCode() {
    final int prime = 31;
    int result = 1;
    result = prime * result + idCategoryCompetenceEnum;
    result = prime * result + idCompetence;
    result = prime * result + ((nameCompetence == null) ? 0 : nameCompetence.hashCode());
    return result;
}

@Override
public boolean equals(Object obj) {
    if (this == obj)
        return true;
    if (obj == null)
        return false;
    if (getClass() != obj.getClass())
        return false;
    CompetenceEntityImpl other = (CompetenceEntityImpl) obj;
    if (idCategoryCompetenceEnum != other.idCategoryCompetenceEnum)
        return false;
    if (idCompetence != other.idCompetence)
        return false;
    if (nameCompetence == null) {
        if (other.nameCompetence != null)
            return false;
    } else if (!nameCompetence.equals(other.nameCompetence))
        return false;
    return true;
}

@Override
public String toString() {
    return "CompetenceEntityImpl [idCompetence=" + idCompetence + ", nameCompetence=" + nameCompetence
            + ", idCategoryCompetenceEnum=" + idCategoryCompetenceEnum + "]";
}

}

package coma.entity.impl;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import coma.entity.CompetenceCriteriaEntity;
import coma.exception.InvalidIDException;

@Entity
@Table(name = "competence_criteria")
public class CompetenceCriteriaEntityImpl implements    CompetenceCriteriaEntity, Serializable {

/**
 * 
 */

@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "id_competence_criteria")
private int idCompetenceCriteria;

@ManyToOne(fetch = FetchType.EAGER, targetEntity = CompetenceEntityImpl.class)
@JoinColumn(name = "id_competence")
CompetenceEntityImpl competenceEntityImpl;

@ManyToOne(fetch = FetchType.EAGER, targetEntity = CriteriaEntityImpl.class)
@JoinColumn(name = "id_criteria")
CriteriaEntityImpl criteriaEntityImpl;

@Column(name = "id_criteria", insertable = false, updatable = false)
private int idCriteria;

@Column(name = "id_competence", insertable = false, updatable = false)
private int idCompetence;



public CompetenceEntityImpl getCompetenceEntityImpl() {
    return competenceEntityImpl;
}


public void setCompetenceEntityImpl(CompetenceEntityImpl competenceEntityImpl) {
    this.competenceEntityImpl = competenceEntityImpl;
}


public CriteriaEntityImpl getCriteriaEntityImpl() {
    return criteriaEntityImpl;
}


public void setCriteriaEntityImpl(CriteriaEntityImpl criteriaEntityImpl) {
    this.criteriaEntityImpl = criteriaEntityImpl;
}


public CompetenceCriteriaEntityImpl() {
}


public CompetenceCriteriaEntityImpl(int idCompetenceCriteria, int idCompetence, int idCriteria) {
    this.idCompetenceCriteria = idCompetenceCriteria;
    this.idCompetence = idCompetence;
    this.idCriteria = idCriteria;
}



@Override
public int getIdCompetenceCriteria() {
    return idCompetenceCriteria;
}

@Override
public void setIdCompetenceCriteria(int idCompetenceCriteria) {
    this.idCompetenceCriteria = idCompetenceCriteria;
}

@Override
public int getIdCompetence() {
    return idCompetence;
}

@Override
public void setIdCompetence(int idCompetence) throws InvalidIDException {
    if (idCompetence < 0) {
        throw new InvalidIDException("The idCompetence must be greater than 0");
    } else {
        this.idCompetence = idCompetence;
    }
}

@Override
public int getIdCriteria() {
    return idCriteria;
}

@Override
public void setIdCriteria(int idCriteria) throws InvalidIDException {
    if (idCriteria < 0) {
        throw new InvalidIDException("The idCriteria must be greater than 0");
    } else {
        this.idCriteria = idCriteria;
    }

}


@Override
public int hashCode() {
    final int prime = 31;
    int result = 1;
    result = prime * result + idCompetence;
    result = prime * result + idCompetenceCriteria;
    result = prime * result + idCriteria;
    return result;
}


@Override
public boolean equals(Object obj) {
    if (this == obj)
        return true;
    if (obj == null)
        return false;
    if (getClass() != obj.getClass())
        return false;
    CompetenceCriteriaEntityImpl other = (CompetenceCriteriaEntityImpl) obj;
    if (idCompetence != other.idCompetence)
        return false;
    if (idCompetenceCriteria != other.idCompetenceCriteria)
        return false;
    if (idCriteria != other.idCriteria)
        return false;
    return true;
}


@Override
public String toString() {
    return "CompetenceCriteriaEntityImpl [idCompetenceCriteria=" + idCompetenceCriteria + ", idCompetence="
            + idCompetence + ", idCriteria=" + idCriteria + "]";
}


}

我对冬眠感到困惑和绝望。。。

共有1个答案

松阳泽
2023-03-14

正如消息所说,您的“mappedBy”值是错误的。它应该是双向关系另一侧链接回此类的字段/属性的名称。e、 gcompetinceEntityImpl。CompetencyCriteriaEntityImpl声明通过字段CompetencyCriteriaEntityImpl进行链接。能力,但这并不存在。相反,mappedBy应该是“competinceEntityImpl”。这可以在任何基本的JPA文档中找到

 类似资料:
  • 问题内容: 我在被注释的对象中建立一对多关系时遇到问题。 我有以下几点: 然后这个 和这个 我在这里做错了什么 问题答案: 该属性正在引用,而该属性是,因此出现错误消息。因此,请将您的映射更改为: 或者将实体属性更改为(这就是我要做的)。 mapledBy参考指示“在我有一个用于查找配置的集合的东西上查找名为’customer’的bean属性。”

  • 您好,我是JPA Spring boot的新手,现在我正在尝试将两个表之间的连接转换为第三个表。所以我有一个医生和病人表,其中有它的属性,一个医生可以检查每个病人,一个病人可以看望每个医生。但是在一次检查中,不能有超过一个病人和一个医生。对于医生,我想保留他们检查过的患者的信息,分别是患者的信息,以及他们检查过的医生的信息。我想创建一个名为DoctorVisit的中间表,其中我有做检查的医生的id

  • 我第一次使用Hibernate,并且很难让它与我的模式一起工作。 我得到了"org.hibernate.注释异常:映射通过引用未知的目标实体属性:学生。教师在Faculty.all学生”。 一些学生共用一个导师。因此,我认为学生和教师的关系是多对多的,但我被告知这是多对多的关系。 Student.java Faculty.java 数据库架构: 在看了留档后,我尝试了几种不同的注释,但我看不出我做

  • 问题内容: 我需要建立一个单向关系,但此错误似乎已映射通过引用未知的目标实体属性(该属性为父级) 这个孩子班 问题答案: 您需要将注释的属性设置为 psyQuestions 而不是 问题 。的值的属性是在关系的另一侧上的类字段的名称,在这种情况下 psyQuestions 所述的类PsyOptions的一侧。

  • 首先,我的课程: 使用者 角色地图。JAVA 当我尝试在服务器上运行这个我有这样的异常:错误创建bean与名称'SessionFactory'定义在ServletContext资源[/WEB-INF/类/base Beans.xml]:调用init方法失败;嵌套的异常org.hibernate.注释异常:映射通过引用一个未知的目标实体属性:com.patpuc.model.ap.users在com

  • 我对Meal和MealGroup之间的关系有问题。Hibernate返回给我:"mappdBy引用未知的目标实体属性"。我有两个实体: 我尝试删除@Join Column和mappedBy。已创建其他表,但我想加入该列。 和 谢谢你的帮助。