NHibernate 拦截器不要求更改多对多集/列表
我有一个使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您应该覆盖 onCollectionUpdate。
比使用集合作为 IPercientCollection 来访问其 CollectionSnapshot 和所有者。
祝你好运!
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?
And then open the session passing it as a parameter like this?