我有两个班级的课程和一个学生,并且创建了三个表(学生,课程,学生课程),我想做的是删除与(学生课程)中与该学生相关的课程表格而不删除学生。
public class Course {
@Id
@GeneratedValue
private int id;
@ManyToMany(mappedBy = "courses", fetch = FetchType.EAGER,cascade =
{CascadeType.ALL})
private Set<Student> students;
}
k
@Entity
public class Student {
@Id
@GeneratedValue
private int id;
@ManyToMany(cascade = {CascadeType.ALL})
@JoinTable(name = "stud_course", joinColumns ={ @JoinColumn(name = "student_id",
referencedColumnName = "id")}, inverseJoinColumns = {@JoinColumn(name = "course_id",
referencedColumnName = "id")})
private Set<Course> courses;