The inverse attribute tells Hibernate if the entity persister manages the collection.
If inverse=true the persister won't manage the collection. So it has to be managed by the other end.
This is not about cascading but establishing who has to write in the database the fact that B belongs to the collection defined in A.
So, in your example the relational representation of the collection is given by a FK A_id in table B.
If you make an instance of B part of the collection A.bagOfBs you have to set that column with the value of the A id.
When inverse is false, the persister of A do manage the collection, so the session will issue a command like: update B set A_id = ?.
Usually you don't want this in many-to-one associations, because the FK column is defined as a one-to-many property on the other side, so an update command for B already set that column. Hence in many-to-one associations you set inverse=true.
Cascading is not related to this behavior. It rather establishes how save, update, save-or-update or replicate operations applied to an entity instance, will apply to the associated instances.
For example, if the association between A and B has cascade=all, as you associate a new instance of B to the collection in A, it will be automatically saved. Or, if you delete A, Hibernate will also delete all Bs.
Hope this help... Indeed, I think the manual is much cleaner...
_________________ --- stefano
Don't forget to rate.
|