我在数据库中有两个名为Student(作为父级)和StudentInfo(作为子级)的表,它们具有一对一的关系。当我删除Parent对象时,应该删除相关的子对象。
我的学生pojo:
@Entity
@Table(name = "student")
public class Student {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int id;
private String studentName;
@OneToOne(cascade= CascadeType.REMOVE)
@JoinColumn(name="id")
private StudentInfo info;
// getters and setters
}
和我的StudentInfo pojo ..
@Entity
@Table(name = "studentInfo")
public class StudentInfo {
@Id
@GeneratedValue(generator = "newGenerator")
@GenericGenerator(name = "newGenerator", strategy = "foreign", parameters = @Parameter(name = "property", value = "student"))
private int id;
private String mobileNo;
@OneToOne
@JoinColumn(name = "id")
private Student student;
// getters and setters
}
当我对Student(父)执行删除操作时,只有父对象被删除但是子对象id没有被删除。我如何删除父和子?