from documentation

Changes made only to the inverse end of the association are not
persisted. This means that NHibernate has two representations in
memory for every bidirectional association, one link from A to B and
another link from B to A. This is easier to understand if you think
about the .NET object model and how we create a many-to-many
relationship in C#:

The non-inverse side is used to save the in-memory representation to
the database. We would get an unneccessary INSERT/UPDATE and probably
even a foreign key violation if both would trigger changes! The same
is of course also true for bidirectional one-to-many associations.



On Dec 18, 11:53 am, skrishna <[email protected]> wrote:
> I have a many-to-many association which is bidirectional.
> Here is the scenario.
>
> I have a User class which has a collection of Group objects.
> The Group class has a collection of User objects.
>
> When I save a user object, the save cascades and saves the group
> objects too.
> Same with the other way saving a group object.
> The deletes also work fine by cascading the deletes only to the
> association table.
>
> The problem happens in this situation:
> I have a User object which has 3 groups in its "Groups" collection.
> when I remove a group from this collection and save the user object,
> the Association table data does not get cleared.
>
> This works fine from the Group side. It is a problem only from the
> Users side, which is declared with inverse="true".
>
> The mapping is as follows:
>
> (Section from User mapping file)
> <bag name="Groups"
>         inverse="true"
>         table="Association" schema="MetadataUseCases_UseCase11"
>         cascade="save-update" generic="true" batch-size="10">
>         <key column="UserId" />
>         <many-to-many column="GroupId" class="Group" />
> </bag>
>
> (Section from Group mapping file)
> <bag name="Users"
>         table="Association" schema="MetadataUseCases_UseCase11"
>         cascade="save-update" generic="true" batch-size="10">
>         <key column="GroupId" />
>         <many-to-many column="UserId" class="User" />
> </bag>
>
> The Association table has the columns UserId and GroupId.
>
> Any help is appreciated!
--~--~---------~--~----~------------~-------~--~----~
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