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.

4

2 回答 2

1

您应该覆盖拦截器的onCollectionUpdate

比使用集合作为IPersistentCollection来访问其 CollectionSnapshot 和所有者。

还有祝你好运!

于 2011-10-21T22:04:01.557 回答
0

您的配置和会话设置是如何实现的?

您是否将拦截器与这样的配置相关联?

config.SetInterceptor(new YouInterceptor());

然后打开会话将它作为这样的参数传递?

if (config.Interceptor != null)
{
    session = factory.OpenSession(config.Interceptor);
}
else
{
    session = factory.OpenSession();
}
于 2011-03-25T11:52:01.087 回答