Development With A Dot

Blog on development in general, and specifically on .NET

Sponsors

News

My Friends

My Links

Permanent Posts

Portuguese Communities

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

Comments

Adam said:

All depends from you session management strategies.

# June 21, 2011 5:56 AM

Ricardo Peres said:

@Adam:

That's what I said: "if you are NOT using FlushMode.Never"

;-)

# June 21, 2011 5:59 AM