3

I need to save a unchanged object via nhibernate to get a database trigger fired.

So how can I tell nhibernate that this object is dirty even if no property has changed?

tshepang
  • 12,111
  • 21
  • 91
  • 136
land79
  • 81
  • 4

2 Answers2

4

There are NHibernate extension points, exactly for this scenario. In this case, we can append custom EventListener or introduce an IInterceptor.

Check this question How to make NHibernate considered property to always be dirty when using dynamic update or insert? for a solution (answer based on IInterceptor)

See the NHibernate documenation 12. Interceptors and events

Community
  • 1
  • 1
Radim Köhler
  • 122,561
  • 47
  • 239
  • 335
  • 1
    The problem with interceptor (finddirty) is that I only have the entity/object itself to decide if non-dirty save is needed or not. But in my scenario there is'nt anything at object scope that I can use for this. so i need to introduce a extra property for this. But I don't want that objects itself know something abouth non-dirty save. This would be the same problem with events to. – land79 Dec 17 '12 at 09:55
4

So in respect to my comment to Radims answer I did the following:

I changed one entry of the loadedstate array of the entity so nhibernate will see it as changed on next save.

I know that this is a bit of a workaround but for me it works so far.

EntityEntry entry = sessImpl.PersistenceContext.GetEntry(dbo);
entry.LoadedState[x] = y;
land79
  • 81
  • 4