Question

I have a situation where I need persist every change in my entities, because changing entity properties physically moves things (or rather reflects that), so if the application is closed (at any time, by close or kill) and started again, it must restart where it left.

Basically what I want is to flush the session each time something becomes dirty. So far I looked at interceptors, but found nothing which suits my needs.

Of course I can do that manually by calling Flush() on every property change, but I would want to avoid introducing persistence code into my entities.

Any hints?

Was it helpful?

Solution

There's no such thing built in into NHibernate (FlushMode.Always flushes only when you re-query), but even if there were, I wouldn't recommend that. You may very well end up with your data being in an inconsistent state. To mitigate this, wrap all your "data-modifying" code in transactions and commit them accordingly.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top