Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hibernate: OnDelete vs cascade=CascadeType.REMOVE

What is the difference between @OnDelete(action=OnDeleteAction.CASCADE) and cascade=CascadeType.REMOVE

I read here: Is there an equivalent annotation for OnDelete in JPA2 that with @OnDelete(action=OnDeleteAction.CASCADE) the cascade will be handled by the DB, while with cascade=CascadeType.REMOVE the cascade will be handled by the ORM (Hibernate).

  1. Could you explain what is the difference between handling by Hibernate vs handling by the DB? How is it done "by the DB"?

  2. Also, I would like to know why should I care about the difference. I mean, why should I choose one attitude over the other.

  3. Last question is, looking at the OnDelete javadoc I was wondering why it says nothing about what is does and why I should use it (BTW where is the inheritance path?). So where are these points documented?

like image 439
rapt Avatar asked Nov 14 '22 15:11

rapt


1 Answers

1-Some database support cascade option and some databases do not :If the database support cascade then hibernate will create schema accordingly and let database to handle cascading.

2-If database handle cascade use it ,other vice hibernate have to query database and this is a performance lost.

3-No idea

like image 197
ayengin Avatar answered Jan 21 '23 20:01

ayengin