java - Delete records from table in many to many relationship? -
i using hibernate many many association. have 3 tables(student,course , student_course). among 3 tables 2 main tables , 1 table intermediate table providing relation ship. when record deleted student corresponding mapping deleted student_course. requirement should delete record course table. consider student_course entries below:
s-id c_id 101 201 102 202 when 101 deleted form student table, first entry above table deleted record corresponding 201 in course table stays is. how can delete record? need execute delete query? many many relation ship not take care? below 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!
you want delete corresponding course if delete student, ok did configuration in student hbm on student => student_course mapping inverse , cascade , same need in student_course hbm student_course => course mapping.
Comments
Post a Comment