CascadeType.ALL,cascade = CascadeType.REMOVE和orphanRemoval之间有什么区别

编程入门 行业动态 更新时间:2024-10-27 13:23:33
本文介绍了CascadeType.ALL,cascade = CascadeType.REMOVE和orphanRemoval之间有什么区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我搜索了答案,但找不到正确的答案.在我们将 FetchType.EAGER 设置为on时, CascadeType.ALL ,cascade = CascadeType.REMOVE , orphanRemoval 有什么区别? @OneToMany 关系?一旦我在删除记录时遇到问题.我已经使用了

I searched the answer but I could not get it properly. What is difference between CascadeType.ALL, cascade = CascadeType.REMOVE, orphanRemoval when we set FetchType.EAGER on @OneToMany relationship? Once I had a problem while deleteing records. I have used following

@OneToMany(cascade = CascadeType.ALL, mappedBy = "companyEntity", fetch = FetchType.EAGER) Set<EmployeeEntity> employeeEntities;

当我尝试删除Employee记录时,它没有显示任何异常,也没有删除记录.但是,当我将 CascadeType.ALL 更改为 CascadeType.REMOVE 时,它就可以了.为什么它不能与 CascadeType.ALL 一起使用,而不能与 CascadeType.REMOVE 一起使用?

When I tried to delete Employee record, it was not showing me any exception and it was not deleteing record. But when I changed CascadeType.ALL to CascadeType.REMOVE then it was working. Why it was not working with CascadeType.ALL rather with CascadeType.REMOVE?

谢谢您提前简单的解释;)

Thank you for simple explanation in advance ;)

推荐答案

这解释了部分问题.

'OrphanRemoval = true'与'CascadeType.REMOVE'

'OrphanRemoval=true' Vs 'CascadeType.REMOVE'

这两个设置之间的区别在于对删除的响应父实体指向的集合中的子对象.

The difference between the two settings is in the response to removing child objects from the collection pointed by parent entity.

如果指定了orphanRemoval = true,则删除的地址实例为自动删除.如果仅指定cascade = CascadeType.REMOVE由于删除关系不是一个自动操作,因此不会采取任何自动操作删除操作.

If orphanRemoval=true is specified the removed address instance is automatically removed. If only cascade=CascadeType.REMOVE is specified no automatic action is taken since removing a relationship is not a remove operation.

更多推荐

CascadeType.ALL,cascade = CascadeType.REMOVE和orphanRemoval之间有什么区别

本文发布于:2023-11-23 19:26:55,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1622610.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:有什么区别   cascade   CascadeType   orphanRemoval   REMOVE

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!