.net - Multiple NHibernate sessions in one Transanction -


i need enlist several nhibernate sessions in 1 transaction. following:

1) create sql connection, dbconn;

2) call isession session = isessionfactory.opensession(dbconn) create first session;

3) call session.begintransaction() begin transaction.

4) later in code, create new session same connection:

isession session2 = isessionfactory.opensession(dbconn)

when attempt run query against session2, following error message:

executereader requires command have transaction when connection assigned command in pending local transaction. transaction property of command has not been initialized.

nhibernate doesn't seem enlist second isession (or, more specifically, command object creates session) in open transaction, though reuse same connection.

is there way have multiple sessions within same transaction?

i cannot use single session because have long-running task loads , creates on 1 million objects. if use 1 isession, performance degrades 3000 database requests per second 20, due performance degradation of nhibernate flushes. solve i'd create short-lived sessions , dispose them quickly.

however, entire process wrapped transaction. if create independent subsequent sessions own connections, bump against table locks held first transaction , freeze. solve need these sessions running within same transaction.

things can do

  • session.getsession() create child sessions same context (connection, transaction, mode)
  • if don't need cascading use statelesssession meant this
  • use session.clear(); after every 50 objects or so

Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -