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

时间:2022-10-09 18:05:34

I have two tables (Resources & Tags) and the third that connects both of them(Resources_tags). How can I delete the many-to-many relationship of a resource with several tags with a HQL query? For example, I want to delete all the tags that a resource have in Resources_tags table.

我有两个表(资源和标签),第三个连接它们(Resources_tags)。如何使用HQL查询删除具有多个标记的资源的多对多关系?例如,我想删除资源在Resources_tags表中的所有标记。

1 个解决方案

#1


0  

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”上指定“cascade”。

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”执行的任何删除都应具有所需的效果。

#1


0  

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”上指定“cascade”。

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”执行的任何删除都应具有所需的效果。