【问题标题】:Hibernate one to many association deletion休眠一对多关联删除
【发布时间】:2020-07-18 10:07:28
【问题描述】:

在与级联启用的一对多双向关联中,休眠中的所有删除孤儿,是否有任何可能休眠尝试使用外键列删除子实体? 它触发了一个额外的查询 delete from child where foreign_key_col = parent_primary_key。

【问题讨论】:

  • 触发“额外查询”是什么意思?一旦删除了相应的主记录,您希望如何删除子记录?

标签: oracle hibernate jpa nhibernate-mapping hibernate-onetomany


【解决方案1】:

对于双向关系,如果删除父实体中的级联。

您可以直接从父级中删除子级。

//set parent as null
child.setParent(null)

//parent.children.iterater and remove it from the iterator.

//then save the parent.
save(parent)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-07-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-21
    • 2012-09-04
    • 1970-01-01
    相关资源
    最近更新 更多