Spring Boot Bootcamp – Workbooks and Challenges
)}

Challenge – Part 2

There is an imbalance in the course_student relationship.

Launch the Starter Project

Screen Shot 2022-08-08 at 11.45.45 PM.png

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

Screen Shot 2022-08-08 at 6.46.02 PM.png

Task 2

Delete the course with an ID of 5. It gets deleted in the course table.

Screen Shot 2022-08-08 at 8.00.05 PM.png

Because course owns the association, associated records are deleted in the join table as well.

Screen Shot 2022-08-08 at 8.08.21 PM.png

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.

Screen Shot 2022-08-08 at 7.35.30 PM.png

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:

  1. Remove mappedBy.
  2. 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.

Screen Shot 2022-08-08 at 7.57.59 PM.png

Good Luck!

Feedback Summary
5.0
3 students
5

100%
4

0%
3

0%
2

0%
1

0%
Written Reviews
There are no written reviews yet.