how can we use foreign key when deleting data in hibernate
I have two tables which are refered by foreign key... I will delete the data from first table using primary key...and also i want to delete that refered data from second table when delete the first table data... is there any开发者_如何学C other way to delete data from both tables in single operation...
I solved that problem by using set tag in mapping file..this is my code it's working fine now
i added these code in xml file
<set name="teamMatch" cascade="delete" inverse="true" table="tbl_team_match">
<key><column name="match_id" not-null="true" /></key>
<one-to-many class="TeamMatch"/>
</set>
and added these code in java file
MatchBean match = (MatchBean) hibernateSession.load(
MatchBean.class, Integer.parseInt(id));
hibernateSession.delete(match);
精彩评论