Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

force nhibernate to save unchanged object (mark it as dirty)

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?

like image 762
land79 Avatar asked Dec 04 '25 17:12

land79


2 Answers

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

like image 51
Radim Köhler Avatar answered Dec 06 '25 12:12

Radim Köhler


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;
like image 40
land79 Avatar answered Dec 06 '25 11:12

land79



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!