I have two classes with ManyToMany relationship.
Student.java
@Entity
public class Student {
@Id
private Long id;
private String name;
@ManyToMany(cascade = {CascadeType.ALL})
@JoinTable(name = "student_class", joinColumns = {@JoinColumn(name = "student_id")},
inverseJoinColumns = {@JoinColumn(name = "class_id")})
private List<Class> classList = new ArrayList<>();
}
Class.java
@Entity
public class Class {
@Id
@GeneratedValue
private Long id;
private String name;
@ManyToMany(mappedBy = "classList",cascade = {CascadeType.ALL})
private List<Student> students;
}
My question is how to implement a POST request in the controller? Do I add class to classList for a student and the student will automatically get inserted into students list?