简体   繁体   English

NHibernate inteceptor不需要在多对多集/列表中进行更改

[英]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. 我有一个使用NHibrenate的应用程序,我正在使用基于拦截器的解决方案进行日志记录/审计。

Basically I have a class inheriting from EmptyInterceptor and overriding OnFlushDirty, OnSave and OnDelete. 基本上我有一个继承自EmptyInterceptor并重写OnFlushDirty,OnSave和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? 如何挂钩NHibrenate并检测这些变化?

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: 使用此hbm映射:

<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. 我正在使用NHibrenate 2.0.1(如果这有任何区别),这不是在项目生命周期中升级NHibrenate的好时机 - 但如果我绝对需要,我会升级。

Thanks. 谢谢。

You should override onCollectionUpdate of the Interceptor. 您应该覆盖Interceptor的onCollectionUpdate

Than use collection as IPersistentCollection to access its CollectionSnapshot and Owner. 比使用集合作为IPersistentCollection来访问其CollectionSnapshot和Owner。

And Good Luck! 还有祝你好运!

How is your configuration and session setup implemented? 您的配置和会话设置如何实现?

Do you associated the Interceptor with the configuration like this? 您是否将Interceptor与此类配置相关联?

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM