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提供程序的数据库生成工具来创建基础数据库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屋!