问题描述
我搜索了答案,但找不到正确的答案.在我们将 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 ;)
推荐答案
这解释了部分问题.
这两个设置之间的区别在于对删除的响应父实体指向的集合中的子对象.
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之间有什么区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!