NHibernate 拦截器不要求更改多对多集/列表

发布于 2024-09-04 17:36:08 字数 1083 浏览 3 评论 0原文

我有一个使用 NHibrenate 的应用程序,并且我正在使用基于拦截器的解决方案进行日志记录/审核。

基本上我有一个继承自 EmptyInterceptor 并重写 OnFlushDirty、OnSave 和 OnDelete 的类。

一切都很完美 - 除了 - 当我从使用多对多映射的集合或列表中添加或删除而不更改任何其他属性时,不会调用任何拦截器方法。

我如何连接 NHibrenate 并检测这些变化?

该类看起来像:

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 ...

}

使用此 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>

我正在使用 NHibrenate 2.0.1(如果这有什么区别的话),这不是项目生命周期中升级 NHibrenate 的好时机 - 但如果我绝对有的话我会升级到。

谢谢。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

(り薆情海 2024-09-11 17:36:09

您应该覆盖 onCollectionUpdate

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

祝你好运!

You should override onCollectionUpdate of the Interceptor.

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

And Good Luck!

美煞众生 2024-09-11 17:36:09

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

你是否将拦截器与这样的配置关联起来?

config.SetInterceptor(new YouInterceptor());

然后打开会话,将其作为参数传递,如下所示?

if (config.Interceptor != null)
{
    session = factory.OpenSession(config.Interceptor);
}
else
{
    session = factory.OpenSession();
}

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();
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文