Reputation: 12621
I am using hibernate many to many association. i have 3 tables(STUDENT,COURSE and STUDENT_COURSE). among 3 tables 2 are main tables and one table is intermediate table for providing relation ship. when record is deleted from STUDENT then corresponding mapping is deleted from STUDENT_COURSE. my requirement is it should even delete record from COURSE table. consider STUDENT_COURSE entries as below:
S-Id C_ID
101 201
102 202
when 101 is deleted form STUDENT table, first entry from above table is deleted but record corresponding to 201 in COURSE table stays as is. how can i delete that record? do i need to execute a delete query? does many to many relation ship does not take care? Below is my configuration:
<set name="course" table="STUDENT_COURSE"
inverse="false" lazy="false" fetch="join" cascade="all" >
<key>
<column name="S_Id" not-null="true" />
</key>
<many-to-many entity-name="COURSE">
<column name="C_Id" not-null="true" />
</many-to-many>
</set>
Thanks!
Upvotes: 1
Views: 886
Reputation: 5380
You want to delete Corresponding Course also if I delete a Student, Ok Like you did the configuration in Student hbm on Student => STUDENT_COURSE mapping for inverse and cascade
, the same you need to do in STUDENT_COURSE hbm also for STUDENT_COURSE => COURSE mapping.
Upvotes: 1