JPA 2.0 orphanRemoval = true删除Cascade上的VS [英] JPA 2.0 orphanRemoval=true VS on delete Cascade

查看:202
本文介绍了JPA 2.0 orphanRemoval = true删除Cascade上的VS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆