简体   繁体   中英

A nhibernate session problem about transactions

I will try to explain in pseudo code.

There're two sessions s1 and s2

int totalEntity = 0;

Thread1
{
s1.BeginTransaction ();
loop (infinite)
{
   totalEntity = s1.List<Entity> ().Count ();
}
s1.EndTransaction ();
}


s2.BeginTransaction ();
s2.Insert<Entity> ();
s2.EndTransaction ();

When i run the s2, the totalEntity still is zero because the s1.Transaction not commited. How can i get the real totalEntity as 1, in the loop?

You can call flush, it'll cause the db to be updated.

I think it's better if the transaction is inside the loop.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM