JPA 2.0 orphanRemoval = true删除Cascade上的VS [英] JPA 2.0 orphanRemoval=true VS on delete Cascade
问题描述
我对JPA 2.0 orphanRemoval
属性有点困惑。
我想我可以看到它是当我使用我的JPA提供程序的数据库生成工具创建基础数据库DDL时,需要在特定关系上具有 ON DELETE CASCADE
。
但是,如果数据库存在并且关系上已经有一个 ON DELETE CASCADE
,这是否不足以级联删除? orphanRemoval
还有什么作用?
欢呼
orphanRemoval
与 ON ON DELETE CASCADE
无关。 p>
orphanRemoval
完全是特定于ORM的内容。它标记子实体,当其不再从父实体引用时被删除,例如,当您从相应的父实体集合中删除子实体时。
ON DELETE CASCADE
是特定于数据库的东西,它会在删除父行时删除数据库中的子行。
I am a little confused about the JPA 2.0 orphanRemoval
attribute.
I think I can see its 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.
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?
Cheers
orphanRemoval
has nothing to do with ON DELETE CASCADE
.
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
is a database-specific thing, it deletes the "child" row in the database when the "parent" row is deleted.
这篇关于JPA 2.0 orphanRemoval = true删除Cascade上的VS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!