If we have a bidirectional association - we need to make one end of the association as inverse.
Consider example of Item - Bid bidirectional association where
From Item to Bid it's one-to-many association
From Bid to Item it's many-to-one association
In Hibernate_Reference : It's mentioned as :
All bi-directional associations need one side as inverse. In a one-to-many association it has to be the many-side.
According to this, the inverse attribute should be @ Bid side. This means we need to specify inverse attribute in Bid.hbm.xml file.
BUT (NOTE THE CONTRADICTION)
In Hibernate In Action Book, it's written in Item.hbm.xml as :
Code:
<class
name="Item"
table="ITEM">
...
<set
name="bids"
inverse="true">
<key column="ITEM_ID"/>
<one-to-many class="Bid"/>
</set>
</class>
The following are few more related questions :
1. When we say many side of association (Bid) do we mean/refer to Bid.hbm.xml ?
2. Does this mean that, if i specify the inverse attribute in Item.hbm.xml (i.e Item Side [One Side of association]), it means ignore the changes made @ item say. Hence if we only call item.getBids().add(bid), no changes
will be made persistent. Instead we are telling Hibernate that it should propagate changes made at the Bid end of the association to the database. i.e when we call bid1.setItem(item) ,it should become persistent ?