"mappedBy reference an unknown target entity property" 休眠,多对多

"mappedBy reference an unknown target entity property" Hibernate, ManyToMany

我尝试使用 Maven 框架为我的程序创建一个数据库。但是,我得到了这种错误。

Invocation of init method failed; nested exception is org.hibernate.AnnotationException: mappedBy reference an unknown target entity property: tugas1.sidok.model.Jadwal_JagaModel.jadwal_jaga in tugas1.sidok.model.DokterModel.jadwal

这是我针对 DokterModel 和 Jadwal_JagaModel

的以下程序

DokterModel.Java

@Entity
@Table(name = "dokter")
public class DokterModel implements Serializable {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "dokter_id")
    private long idDokter;

    @Size(max = 255)
    @Column(name = "NIP", nullable = false)
    private String nip;

    @Size(max= 255)
    @Column(name="NIK", nullable = false)
    private String nik;

    @Size(max = 255)
    @Column(name = "nama", nullable = false)
    private String nama;

    @Column(name = "tanggal_lahir", nullable = false)
    private Date tanggalLahir;

    @Column (name = "jenis_kelamin", nullable = false)
    private Boolean jenisKelamin;

    @Size(max = 255)
    @Column (name = "tempat_lahir")
    private String tempatLahir;

    @ManyToMany(mappedBy = "jadwal_jaga")
    private List<Jadwal_JagaModel> jadwal;

    //Setter getter //

Jadwal_JagaModel.Java

@Entity
@Table(name = "jadwal_jaga")
public class Jadwal_JagaModel {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "jadwal_jaga_id")
    private long id;

    @Size(max = 255)
    @Column(name = "hari", nullable = false)
    private String hari;

    @ManyToMany(cascade = {CascadeType.ALL})
    @JoinTable(
            name = "Dokter_Jadwal_Jaga",
            inverseJoinColumns = {@JoinColumn(name = "dokter_id", referencedColumnName = "dokter_id")},
            joinColumns = {@JoinColumn(name = "jadwal_jaga_id",referencedColumnName = "jadwal_jaga_id")}
    )
    private List<DokterModel> jadwalDokters;

// Setter getter //

我知道问题出在 DokterModel.Java 中的 mappedBy,但是,我不确定它应该是什么以及 mappedBy 是如何工作的?这是我第一次使用 Hibernate,因此非常感谢任何帮助。

您应该按如下代码更改映射:

@ManyToMany(mappedBy = "jadwalDokters")
private List<Jadwal_JagaModel> jadwal;

有关此问题的更多信息,请查看 here