@OneToMany: One Student To Many Courses.
@JoinTable(name = "Enrollment"): Join Enrollment table.
joinColumns: with use "student_id" to link Student and enrollment tables.
inverseJoinColumns: Here the source table become "Enrollment", not "Stduent" anymore. Target table become "Course" table.
CascadeType.ALL
is that the persistence will propagate (cascade) all EntityManager
operations (PERSIST, REMOVE, REFRESH, MERGE, DETACH
) to the relating entities. Which means if we delete a student, will also delete the Enrollemnt data from Enrollment table.
FetchType.EAGER: Which means when loading a student related data, it will also load course data which related to that student.
For example;
In Course table:
A column "department":
@ManyToOne @JoinColumn(name="course_dept_id") private Department department;
In Department table:
@OneToMany(mappedBy="department")