Event Listener not firing on hasManyToMany mapped property

Rob Booth's Avatar

Rob Booth

18 Oct, 2010 09:59 PM via web

I'm implementing automatic auditing on an app I'm working on and I'm
having a problem getting the PostUpdateEvent listener to fire when I
change a property which is mapped as a HasManyToMany.

Below is my map. If a change is made to any of the properties other
than "AdministersUnit" the PostUpdateEvent Listener is fired on the
update.
If I change more than one property and AdministersUnit the postupdate
still doesn't pickup that AdministersUnit has changed. I've just
tried it with a PreUpdate event listener and the same behaviour is
there.

If anyone have any suggestions or a workaround I would be very
grateful!

public class UserMap : ClassMap {

   public UserMap()
   {
       Id(x => x.Id);
       Map(x => x.UserName).Not.Nullable().Length(50);
       Map(x => x.Name).Length(100);
       Map(x => x.Email).Length(100);
       References(x => x.Unit).Nullable();
       Map(x => x.IsAdmin).Default("'false'");
       Map(x => x.WarningMessagesOn).Default("'true'");
       HasManyToMany(x => x.AdministersUnit).LazyLoad();
   }

}

Cheers

Rob

  1. Support Staff 2 Posted by Paul Batum on 19 Oct, 2010 07:05 AM

    Paul Batum's Avatar

    I haven't tried auditing a many-to-many relationship, but I can see how it
    might be a little bit different to other auditing scenarios (because neither
    the User, nor the Unit is changing - its the joining table that is
    changing).

    You might be best off asking for help on the nhibernate
    users<http://groups.google.com/group/nhusers/> mailing
    list as this is really a question that is specifically about NHibernate's
    behavior. If they ask you for an xml version of your mappings, see here:
    http://wiki.fluentnhibernate.org/Fluent_configuration#Exporting_mappings

    On Tue, Oct 19, 2010 at 9:01 AM, Rob Booth <
    ***@tenderapp.com<tender%***@tenderapp.com>
    > wrote:

  2. 3 Posted by Rob Booth on 19 Oct, 2010 07:27 AM

    Rob Booth's Avatar

    Hi Paul,

    Thanks for the response, I'll post the query there too.
    Yes, I can see that it's the 'table in the middle' of the many to many that's being updated and I was wondering if this was the problem.

    Cheers

    Rob

Reply to this discussion

Preview Comments are parsed with Markdown. Help with syntax

Attached Files

    You can attach files up to 10MB

    What comes next? 'Monday Tuesday Wednesday ?????'