我试图使用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 中映射的,但是,我不确定应该是什么,以及mapBy的工作原理是什么?这是我第一次使用Hibernate,因此非常感谢您提供任何帮助。
答案 0 :(得分:1)
您应通过以下代码更改映射:
@ManyToMany(mappedBy = "jadwalDokters")
private List<Jadwal_JagaModel> jadwal;
有关此问题的更多信息,请查看here。