I have 3 tables in my database: Students, Courses and Students_Courses
Students can have multiple courses and courses can have
You just need to Remove cascade = CascadeType.ALL in Student class only no change is required in Courses class
and add the below code cascade = {CascadeType.PERSIST,CascadeType.MERGE,CascadeType.DETACH}..
It means while deleting owner class record it will not delete a non-owner record.
After this, On Delete it will delete only from Student table and student_course. course table data remains the same.