I tried to make a DB for my program using Maven framework. However, I got this kind of error.
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
This is my following program for DokterModel and 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 //
I am aware that the problem is mappedBy within the DokterModel.Java, however, I am not sure on what should it be and how does mappedBy work? This is my first time on using Hibernate, so any kind of help is appreciated.
You should change mapped by code like this:
@ManyToMany(mappedBy = "jadwalDokters")
private List<Jadwal_JagaModel> jadwal;
for more about this problem look here.