I have a Many-to-Many relationship between Faculty and Student entities in a Spring Boot JPA application.
- Faculty has a List students mapped using @ManyToMany, and it is the owning side of the relationship.
- Student has a List faculties, mapped with mappedBy="students".
I have helper methods (addStudent() in Faculty and addFaculty() in Student) that ensure bidirectional mapping.
However, when I persist faculty and students using saveAll(), I notice unexpected and inconsistent records in the join table (student_faculty).
Example of incorrect records in the join table:
sid | sname |
---|---|
1003 | Charles |
1004 | Dennis |
1005 | Elon |