I have been trying to get to grips with Hibernate's inverse attribute,
and it seems to be just one of those things that is conceptually
difficult.

The gist that I get is that when you have a parent entity (e.g.
Parent) that has a collection of Child objects using a one-to-many
mapping, setting inverse=true on the mapping tells Hibernate that 'the
other side (the Child) has responsibility to update itself to maintain
the foreign key reference in its table'.

Doing this appears to have 2 benefits when it comes to adding Children
to the collection in your code, and then saving the Parent: you save
an unneccessary hit on the database (because without inverse set,
Hibernate thinks it has two places to update the FK relationship) (see
http://nhprof.com/Learn/Alert?name=SuperfluousManyToOneUpdate), and
according to the official docs:

"If the column of a association is declared NOT NULL, NHibernate may
cause constraint violations when it creates or updates the
association. To prevent this problem, you must use a bidirectional
association with the many valued end (the set or bag) marked as
inverse="true"."

This all seems to make sense so far. What I don't get is this: when
would you NOT want to use inverse=true on a one-to-many relationship?

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to