简体   繁体   English

删除休眠(HQL)中两个表之间的关系

[英]Delete relationship between two tables in Hibernate (HQL)

I have two tables (Resources & Tags) and the third that connects both of them(Resources_tags). 我有两个表(资源和标签),第三个表连接了两个表(Resources_tags)。 How can I delete the many-to-many relationship of a resource with several tags with a HQL query? 如何通过HQL查询删除带有多个标签的资源的多对多关系? For example, I want to delete all the tags that a resource have in Resources_tags table. 例如,我要删除资源在Resources_tags表中具有的所有标签。

If your two tables are "A" and "B" then when you set up your two tables you need to specify "cascade" on table "A". 如果两个表分别是“ A”和“ B”,则在设置两个表时,需要在表“ A”上指定“层叠”。

like this: 像这样:

<bag name="A"
  inverse="true"
  lazy="false"
  cascade="all">
  <key column="SOME_ID"/>
  .....

Now any deletes performed on "A" should have the desired effect. 现在,对“ A”执行的所有删除都应具有所需的效果。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM