2
votes

I have not used hibernate that much.So, Stuck on a point when inverse and cascade comes into the picture. I know that inverse tells hibernate about the owning entity which holds the responsibility to update their relationship and Cascade will tell hibernate to first save the entity and then its dependent entity.

I was just wondering if it's mandatory to declare cascasde="all" and inverse="true" in the same entity. Can we declare one as owning entity by inverse and cascade property in other entity. Please throw light on this?

Thanks

1

1 Answers

1
votes

Cascading only makes sense when being propagated from a Parent to a Child (one-to-many or one-to-one). It makes no sense for many-to-one or many-to-many, since you don't want to delete a Parent whenever the Child is removed.

Inverse is for bidirectional associations, and most often it's on the same side with cascade, but that's because the many-to-one side is much more efficient (to control the association) than the one-to-many one.

You can also have a one-to-many unidirectional association with cascade, and since this is the single association side, it's the one controlling it as well.