Nhibernate Flush works commit doesn't -


sorry if question doesn't have detail i'm new nhibernate not sure how phrase. i'm wondering why calling session flush in web application not throw error commit would.

i have code normally:

session.saveorupdate(item); session.flush(); 

but if call session.commit() a different object same identifier value associated session error

doesn't commit , flush work same?

the nonuniqueobjectexception, experiencing, thrown in scenarios, when:

  • the current isession instance called id, e.g. .get<tentity>(id), , keeps reference item a
  • the same isession instance called persist (saveorupdate) item b ,
    • both items have same key (itema.id == itemb.id)
    • both different references (itema != itemb)

so, if happens, nonuniqueobjectexception ("a different object same identifier...") thrown.

the flush() , configuration via flushmode implementation of concept of detached persistence layer. working/interacting session, calling read operations (mostly executed immedietly or provided cache), calling write operations - queued. not executed. no insert, update, delete issued db engine.

only when flush() called, session "synchronization" of changes db. advantage (one of many) nhibernate can manage order of write statements. see:

9.6. flush

the order of issued statements:

  • all entity insertions, in same order corresponding objects saved using isession.save()
  • all entity updates
  • all collection deletions
  • all collection element deletions, updates , insertions
  • all collection insertions
  • all entity deletions, in same order corresponding objects deleted using isession.delete()

and finally, snippet of enum flushmode, configure flush() call:

/// <summary> represents flushing strategy.</summary> /// <remarks> /// flush process synchronizes database state session state detecting state /// changes , executing sql statements /// </remarks> [serializable] public enum flushmode {     /// <summary>     /// special value unspecified flush mode (like <see langword="null" /> in java).     /// </summary>     unspecified = -1,         /// <summary>     /// <c>isession</c> never flushed unless <c>flush()</c> explicitly     /// called application. mode efficient read     /// transactions     /// </summary>     never = 0,         /// <summary>     /// <c>isession</c> flushed when <c>transaction.commit()</c> called     /// </summary>     commit = 5,         /// <summary>     /// <c>isession</c> flushed before query execution in order     /// ensure queries never return stale state. default flush mode.     /// </summary>     auto = 10,         /// <summary>     /// <see cref="isession"/> flushed before every query.     /// unnecessary , inefficient.     /// </summary>     = 20 } 

Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -