开发者

Nhibernate listeners does not work correctly

开发者 https://www.devze.com 2022-12-17 22:58 出处:网络
I am using NHibernate (v 2.1.0.4000) and try to use an event Listener for an update action. I used the following code to add a listener to the Nhibernate Configuration.

I am using NHibernate (v 2.1.0.4000) and try to use an event Listener for an update action.

I used the following code to add a listener to the Nhibernate Configuration.

var configuration = new Configuration();    
configuration.SetListener(ListenerType.Update, new UpdateListener());  
_sessionFactory = configuration.BuildSessionFactory();

When I am updating two items, the first item does not get to the "PerformUpdate" function of the listener. However, when updating the second item, the function is being called.

How can this happen?

---Edited---

While debugging I found out that on the "OnSaveOrUpdate" of the Listener , the following code is being executed:

object obj4 = session.PersistenceContext.UnproxyAndReassociate(@event.Entity);
@event.Entity = obj4;
@event.开发者_如何转开发Entry = session.PersistenceContext.GetEntry(obj4);

I expected that @event.Entry was null, but it was not null and had a status Loaded. What should really happen when calling the GetEntry method?


Can you show the code for your listener? Have you used a profiler to make sure that updates are issued for both items? I can see this happening if there are no changes to an item so no update is issued.

Edited to add: I think you're using the older Listener implementation. I suggest using the new style (there's also ISaveOrUpdateEventListener). Are you implementing an auditing function?

I also suggest that you verify that an update is issued for the first item. I know you said you're sure it's been changed, but you should also check that NH thinks it's been changed. It's always a good idea to eliminate the obvious problems when debugging something like this.

0

精彩评论

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