What is the difference between CascadeType.ALL, cascade = CascadeType.REMOVE and orphanRemoval

I was looking for an answer, but I could not understand it correctly. What is the difference between CascadeType.ALL , cascade = CascadeType.REMOVE , orphanRemoval when we set the FetchType.EAGER to @OneToMany ? As soon as I had a problem when deleting records. I used the following

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

When I tried to delete the Employee record, it did not show me any exceptions and did not delete the record. But when I changed CascadeType.ALL to CascadeType.REMOVE , then it worked. Why didn't he work with CascadeType.ALL rather with CascadeType.REMOVE ?

Thanks for the simple explanation in advance;)

+6
source share
1 answer

This explains part of your question.

'OrphanRemoval = true' Vs 'CascadeType.REMOVE'

The difference between the two settings is the response to the removal of the child objects from the collection specified by the parent object.

If orphanRemoval = true is specified, the remote address instance is automatically deleted. If only cascade = CascadeType.REMOVE is specified, no automatic action is taken because deleting a relationship is not a delete operation.

+2
source

Source: https://habr.com/ru/post/980748/


All Articles