0

I have been working on Spring Boot and JPA for quite some time and this question is raised several times. How should one decide to choose the right cascade types for entity relationships?
A scenario-
I have 2 entities- User and Category. Now, I want a many-to-many relationship between these entities such that the relationship follows following rules-

  1. When any entity is deleted, the other side is not deleted.
  2. The categories are pre-defined in the database, therefore, adding/updating the user entity must not add/update the category entity.
  3. Any updation to category must not be propagated to user entity.

Can somebody please help me understand that how to decide the right cascade types. In the above scenario, its clear that I don't have to use CascadeType.REMOVE. But, I am not sure about others- REFRESH, PERSIST and especially MERGE and DETACH.
Please help!!

ayush
  • 464
  • 5
  • 17
  • I'd highly recommend to obey everything Vlad Mihalcea and Thorben Janssen suggest. https://vladmihalcea.com/a-beginners-guide-to-jpa-and-hibernate-cascade-types/ You will find tons of great advices on their blogs. – Slevin Jul 26 '23 at 10:24

0 Answers0