NHibernate Pitfalls: Flushing Changes

This is part of a series of posts about NHibernate Pitfalls. See the entire collection here.

One common thing when saving changes with NHibernate is forgetting to flush. If you don’t flush, no changes will be sent to the database.

One of the many reasons that using a transaction is recommended is that, when the transaction commits, it automatically flushes the session, sending all updates, inserts and deletes in memory to the database – at least, if you are NOT using FlushMode.Never.

This is particularly serious when using stateless sessions, because they don’t have a Flush method (if you aren't using batching, in which case, SQL commands are sent immediately).

So, to save you from problems, always use transactions.

Bookmark and Share

                             

2 Comments

Comments have been disabled for this content.