【发布时间】:2017-11-18 11:03:02
【问题描述】:
我正在尝试删除家长学生或家长课程,但出现此错误:
原因:org.postgresql.util.PSQLException:错误:更新或删除表“student”违反了表“registration”上的外键约束“fkeyvuofq5vwdylcf78jar3mxol”
RegistrationId 类是注册类中使用的复合键。我正在使用 Spring data jpa 和 spring boot。
我做错了什么?我知道在删除父级时放置 cascadetype.all 也应该删除子级,但它却给了我一个错误。
@Embeddable
public class RegistrationId implements Serializable {
@JsonIgnoreProperties("notifications")
@OneToOne(cascade=CascadeType.ALL)
@JoinColumn(name = "student_pcn", referencedColumnName="pcn")
private Student student;
@JsonIgnoreProperties({"teachers", "states", "reviews"})
@OneToOne(cascade=CascadeType.ALL)
@JoinColumn(name = "course_code", referencedColumnName="code")
private Course course;
注册类
@Entity(name = "Registration")
@Table(name = "registration")
public class Registration {
@EmbeddedId
private RegistrationId id;
【问题讨论】:
标签: postgresql spring-boot spring-data-jpa