Hibernate 多对多 只删除中间表记录,是“只”删除,哪位大神能帮我看一下? 15
删除语句:能获取u_id,house_idpublicvoidremoveUser(Stringu_id,Stringhouse_id){Useru=this.findB...
删除语句:能获取u_id,house_id
public void removeUser(String u_id, String house_id) {
User u = this.findById(u_id);
HouseDetail hd = (HouseDetail) this.getHibernateTemplate().get(HouseDetail.class, house_id);
u.getHouses().remove(hd);
this.updateUser(u);
}
用户表user 房屋表housedetail 多对多关系表user_house
HouseDetail.hbm.xml
<set name="users" table="USER_HOUSE" lazy="true"
cascade="save-update" inverse="true">
<key column="house_id" />
<many-to-many class="com.neusoft.crm.tyj.entity.user.User"
column="user_id" />
</set>
User.hbm.xml
<set name="houses" table="USER_HOUSE" lazy="false"
cascade="save-update" inverse="false" >
<key column="user_id" />
<many-to-many class="com.neusoft.crm.tyj.entity.house.HouseDetail"
column="house_id" />
</set> 展开
public void removeUser(String u_id, String house_id) {
User u = this.findById(u_id);
HouseDetail hd = (HouseDetail) this.getHibernateTemplate().get(HouseDetail.class, house_id);
u.getHouses().remove(hd);
this.updateUser(u);
}
用户表user 房屋表housedetail 多对多关系表user_house
HouseDetail.hbm.xml
<set name="users" table="USER_HOUSE" lazy="true"
cascade="save-update" inverse="true">
<key column="house_id" />
<many-to-many class="com.neusoft.crm.tyj.entity.user.User"
column="user_id" />
</set>
User.hbm.xml
<set name="houses" table="USER_HOUSE" lazy="false"
cascade="save-update" inverse="false" >
<key column="user_id" />
<many-to-many class="com.neusoft.crm.tyj.entity.house.HouseDetail"
column="house_id" />
</set> 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询