开发者

NHibernate inteceptor not called for changes in many-to-many set/list

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 开发者_如何学Cset 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.


You should override onCollectionUpdate of the Interceptor.

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

And Good Luck!


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();
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜