There are 7 cascade options available for Hibernate . I would like to clarify exactly what behavior to expect from each of them. And although the effect is intuitively clear under the name, but not everywhere as clearly as we would like.

I will describe how I understand, and you please correct me where I am wrong, and complete the gaps.

  1. none (default) - no transactions lead to not creating, not updating, not deleting child objects.

  2. save - when creating a new object, children are also created if there are none. And in other cases, the option none .

  3. update - when an object is updated, the children are updated only if they exist and there are changes in them. And in other cases, the option none .

  4. save-update - 2 + 3 points.

  5. delete - deleting deletes all children.

  6. all - 4 + 5 points.

  7. all-delete-orphan - it’s not at all clear what he is doing.

    1 answer 1

    Orphan removal - if you have an association of one to many, and you want to remove an entity, then all you need to do is remove it from the collection. This is useful when you have two-way communication. Without this option it is necessary to break the connection from both sides.