Why does NHibernate save objects when I never execute session.Save?

I am using NHibernate with Fluent NHibernate.

I have a code where I start a transaction, then I enter a loop that creates several objects. For each object, I check certain conditions. If these conditions are met, then I execute session.SaveOrUpdate () for the object. At the end of the loop, I issue a commit transaction.

I have a breakpoint in the session.SaveOrUpdate command, proving that it was never reached (because the conditions were not met by any of the objects in the loop). However, when the transaction is completed, the objects are saved!

I use AuditInterceptor and set a breakpoint in the OnSave method. It is called, but the stack trace returns only to the statement that completes the transaction.

There are no objects currently running SaveOrUpdate, so cascading does not explain.

Why does NHibernate save these objects?

+5
source share
2 answers

From NHibernate ISession.Update stream:

This is normal and default behavior :

Hibernate , . , . EntityManager, , - . , , . .

2:

Q) Save ?

() , (, ). Update , .

NHibernate ( ) :

, NHibernate , NHibernate Session.Update(myObj)!

: Session.FlushMode FlushMode.Never. , : tx.Commit() session.Flush(). , /. , session.Evict(yourObj), NHibernate db.

+11

- FlushMode.Commit( ). , , .

FlushMode, . , FlushMode.Manual.

, !

+5

All Articles