Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the difference between @CascadeOnDelete and CascadeType.REMOVE annotations?

At first I've expected that with CascadeType.REMOVE I'll be able to delete foreign keys in my table , but I sill got an exception. But with @CascadeOnDelete it's ok .What's the difference between the two annotations?

EDIT: I've saw the DataNucleus' comment.Cascade on delete comes from org.eclipse.persistence.annotations.CascadeOnDelete .Which raises the question how good idea is to be used.

like image 769
npocmaka Avatar asked Nov 22 '12 07:11

npocmaka


People also ask

What is CascadeType remove?

3. CascadeType. REMOVE. As stated earlier, marking a reference field with CascadeType. REMOVE is a way to delete a child entity or entities whenever the deletion of its parent happens.

What is the difference between remove and delete in Java?

Remove and Delete are defined quite similarly, but the main difference between them is that delete means erase (i.e. rendered nonexistent or nonrecoverable), while remove denotes take away and set aside (but kept in existence).


1 Answers

When you use CascadeType.Remove at the time the cascading will be handled by the ORM tool but when you want the cascading to be handled by the database you can use @CascadeOnDelete.but when you are using @CascadeOnDelete , make sure the Database you are using should support cascading.

like image 139
Pawan Choure Avatar answered Nov 15 '22 11:11

Pawan Choure