我的Patientbooking class
使用了加入表。以下是代码。 Appointment
没有Patientbooking
。
public class Patientbooking implements Serializable {
...
@OneToMany(fetch = FetchType.EAGER, cascade = {CascadeType.PERSIST})
@JoinTable
(
name="patientbooking_appointments",
joinColumns={ @JoinColumn(name="patientbooking_id", referencedColumnName="id") },
inverseJoinColumns={ @JoinColumn(name="appointments_id", referencedColumnName="id", unique=true) }
)
private List<Appointment> appointments;
...
}
当我删除Appointment
时,我收到此错误。
Internal Exception: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Cannot delete or update a parent row: a foreign key constraint fails (`soebala/patientbooking_appointments`, CONSTRAINT `patientbooking_appointments_ibfk_1` FOREIGN KEY (`appointments_id`) REFERENCES `appointments` (`id`))
答案 0 :(得分:0)
由于错误表示您正在执行约束违规。加入你的代码
cascade = {CascadeType.PERSIST, CascadeType.REMOVE})