Challenge – Part 2
There is an imbalance in the course_student
relationship.
Launch the Starter Project
Task 1
Make 4 PUT
requests:
localhost:8080/course/1/student/1
localhost:8080/course/5/student/1
localhost:8080/course/1/student/2
localhost:8080/course/6/student/2
Task 2
Delete the course with an ID of 5. It gets deleted in the course table.
Because course
owns the association, associated records are deleted in the join table as well.
Now, try deleting the student with an id of 2.
{ "timestamp": "08-08-2022 07:19:05", "message": [ "Data Integrity Violation: we cannot process your request." ] }
Ideally, deleting a student would also remove associated records in the join table.
But student
is the non-owning side of the association, and cannot make changes to the join table.
Task 3
In order for student
to be equal in managing the relationship, you need to:
- Remove
mappedBy
. - Make sure that
student
owns the join table as well.
@JoinTable( name = "course_student", joinColumns = @JoinColumn(name = "student_id", referencedColumnName = "id"), inverseJoinColumns = @JoinColumn(name = "course_id", referencedColumnName = "id") )
Task 4
Make 2 PUT
requests:
localhost:8080/course/1/student/1
localhost:8080/course/1/student/2
Then delete the student with an id of 2.
Good Luck!
Feedback Summary
5.0
4 students
5
100%
4
0%
3
0%
2
0%
1
0%
Written Reviews
There are no written reviews yet.