0
votes

I am having confusion in Hibernate one to many mapping with inverse = true.

1.Inverse provides the bidirectional mapping . we put it on collection side and other side is going to take the owner ship. 2.Inverse and Cascade both are used for different purpose.

3.In Casecade = all Hibernate will save the parent with its association in one call.

4.In Cascade =none we need to make different calls to save parent and its childs.

5.In cascade = all and inverse =true there will be one less update query to update constraint in one to many case.

But In case of cascade= none either inverse= true or inverse=false(In one to many) , I am not able to find any changes in sql queries.

So my quesion is In case of cascade = none what exactly inverse=true does.

1

1 Answers

0
votes

cascade and inverse ae orthogonal notions.

inverse simply says that the association is a bidirectional one, mapped by the other side of the association. It makes the other side the owner of the association.

Only one side of an associaion is the owner side, and Hibernate only considers the owner side when persisting. This means that if an entity a has a set of Bs containing b1, b2 and b3, but none of these B instances references a as their parent, Hibernate won't persist the association, because the owner side (B) says: I'm not linked to any parent A.