BeanCreationException 关于创建@manytomany 实体关系

BeanCreationException on creating @manytomany entity relationship

我正在创建三个 tables Doctor、Patient 和 Specialty。病人可以只有一个全科医生,但一个医生可以是许多病人的全科医生。每个医生都有自己的专业(例如神经外科医生、心脏病专家、泌尿科医生等)当我尝试在医生和专业之间建立多对多连接时 table 我收到错误消息“创建名称为 [ 的 bean 时出错=24=] 在 class 路径资源中定义”由 BeanCreationException 引起,特别是 mappedBy 引用未知目标实体 属性。由于我是 spring 引导的新手,如果有人能向我解释,我将非常高兴。提前谢谢你

基础实体class:

@MappedSuperclass
public class BaseEntity {

    @Id
    @GeneratedValue(strategy= GenerationType.IDENTITY)
    private long id;
}

医生class:

@Entity
@Table(name="doctor")
public class Doctor extends BaseEntity{

    private String name;

    @ManyToMany(mappedBy ="doctor")
    private Set<Specialty> specialties;

    @OneToMany(mappedBy ="doctor")
    private List<Patient> GpOfPatients;

}

患者class:

@Entity
@Table(name="patient")
public class Patient extends BaseEntity{

    private String name;
    private String EGN;
    private boolean insurancesPaidInLastSixMonths;

    @ManyToOne
    @JoinColumn(name="gp_id")
    private Doctor doctor;

}

专业class:

@Entity
@Table(name="specialty")
public class Specialty extends BaseEntity{

    private String specialtyName;

    @ManyToMany
    @JoinTable(name="doctors_specialties",joinColumns = @JoinColumn(name="specialty_id"),
    inverseJoinColumns = @JoinColumn(name="doctor_id"))
    private Set<Doctor> doctors;

}

在医生class中,你将specialties映射到doctor,但在专业中,医生集合的名称是doctors,因此无法映射。

您应该更改您的医生 class,如下所示:

@Entity
@Table(name="doctor")
public class Doctor extends BaseEntity{

    private String name;

    @ManyToMany(mappedBy ="doctors")
    private Set<Specialty> specialties;

    @OneToMany(mappedBy ="doctor")
    private List<Patient> GpOfPatients;

}