What is the purpose of CascadeType in Spring Data JPA / Hibernate?


Your thoughts?

EatFreshRupesh |

CascadeType is an option that specifies how related entities should be treated...

let's say you have a one-to-many relationship between courses and students...

in your @Entity class you may have something like:

@OneToMany(cascade = CascadeType.ALL)

This is saying that every operation you perform on this entity, every associated entity will get the same treatement,

So if you delete a parent entity all of it's children (associations) will also get deleted.

Sometimes this makes sense. Sometimes it doesn't. BE CAREFUL in using this as it can have unexpected consequences...

Robert Ramirez | 0

The default CascadeType is no cascade type fyi