<<What I don't get is this: when would you NOT want to use
inverse=true on a one-to-many relationship? >>

In monodirectional relationships.

I would guess the reason this is not "happening by default" in
bidirectional one-to-many refs is to have consistent behaviour with
other mappings such as many-to-many refs where you need to choose one
side. I'm not sure though...

To answer your question - if you have have a bidirectional one-to-many
rel, always use inverse=true.

/Roger

On Jun 30, 2:49 pm, James Allen <[email protected]>
wrote:
> 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) 
> (seehttp://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