4

I have an application that uses NHibrenate and I'm using an interceptor based solution for logging/auditing.

Basically I have a class inheriting from EmptyInterceptor and overriding OnFlushDirty, OnSave and OnDelete.

Everything works perfectly - except - when I add or remove from a set or list that is mapped using many-to-many without changing any other properties none of the interceptor methods are called.

How can I hook into NHibrenate and detect those changes?

The class looks like:

public class SomeClass
{
  ... properties ..
  private Iesi.Collections.ISet _setOfOthers = new Iesi.Collections.HashedSet();
  public virtual Iesi.Collections.ISet SetOfOthers
  {
    get { return _setOfOthers; }
    set { _setOfOthers = value; }       
  }
  ... some more properties ...

}

With this hbm mapping:

<class name="MyAssembly.SomeClass, MyAssembly" table="[SomeClass]">
   ... properties ..
   <set name="SetOfOthers" table="SomeClass_SetOfOthers" cascade="none">
      <key column="Owner" />
      <many-to-many column="Item" class="MyAssembly.OtherClass, MyAssembly" />
   </set>
   .. some more properties ...
</class>

I'm using NHibrenate 2.0.1 (if that makes any difference), this is not a good time in the project life cycle to upgrade NHibrenate - but I will upgrade if I absolutely have to.

Thanks.

Nir
  • 29,306
  • 10
  • 67
  • 103

2 Answers2

1

You should override onCollectionUpdate of the Interceptor.

Than use collection as IPersistentCollection to access its CollectionSnapshot and Owner.

And Good Luck!

Sergei Krivonos
  • 4,217
  • 3
  • 39
  • 54
0

How is your configuration and session setup implemented?

Do you associated the Interceptor with the configuration like this?

config.SetInterceptor(new YouInterceptor());

And then open the session passing it as a parameter like this?

if (config.Interceptor != null)
{
    session = factory.OpenSession(config.Interceptor);
}
else
{
    session = factory.OpenSession();
}
Benjamin
  • 291
  • 3
  • 12
  • Hi, you misunderstood my question (my fault, I wasn't specific enough) I've set the interceptor and the interceptor methods are called for everything except when I add or remove from a set or list that is mapped using many-to-many without changing any other properties. – Nir Mar 27 '11 at 12:46