JPA orphanRemoval=true 与 ON DELETE CASCADE DML 子句有何不同 [英] How does JPA orphanRemoval=true differ from the ON DELETE CASCADE DML clause
问题描述
我对 JPA 2.0 orphanRemoval
属性有点困惑.
I am a little confused about the JPA 2.0 orphanRemoval
attribute.
我认为当我使用我的 JPA 提供程序的 DB 生成工具来创建底层数据库 DDL 以在特定关系上具有 ON DELETE CASCADE
时,我可以看到它是必要的.
I think I can see it is needed when I use my JPA provider's DB generation tools to create the underlying database DDL to have an ON DELETE CASCADE
on the particular relation.
然而,如果数据库存在并且它已经在关系上有一个ON DELETE CASCADE
,这还不足以适当地级联删除吗?orphanRemoval
还有什么作用?
However, if the DB exists and it already has an ON DELETE CASCADE
on the relation, is this not enough to cascade the deletion appropriately? What does the orphanRemoval
do in addition?
干杯
推荐答案
orphanRemoval
与 ON DELETE CASCADE
无关.
orphanRemoval
完全是特定于 ORM 的东西.当不再从父"实体引用时,它将子"实体标记为要删除,例如当您从父实体的相应集合中移除子实体时.
orphanRemoval
is an entirely ORM-specific thing. It marks "child" entity to be removed when it's no longer referenced from the "parent" entity, e.g. when you remove the child entity from the corresponding collection of the parent entity.
ON DELETE CASCADE
是一个数据库特定的东西,它在删除父"行时删除数据库中的子"行.
ON DELETE CASCADE
is a database-specific thing, it deletes the "child" row in the database when the "parent" row is deleted.
这篇关于JPA orphanRemoval=true 与 ON DELETE CASCADE DML 子句有何不同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!