简体   繁体   English

A nhibernate session 关于事务的问题

[英]A nhibernate session problem about transactions

I will try to explain in pseudo code.我将尝试用伪代码进行解释。

There're two sessions s1 and s2有两个会话 s1 和 s2

int totalEntity = 0; int 总实体 = 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.当我运行 s2 时,totalEntity 仍然为零,因为 s1.Transaction 未提交。 How can i get the real totalEntity as 1, in the loop?我怎样才能在循环中获得真正的totalEntity 1?

You can call flush, it'll cause the db to be updated.你可以调用flush,它会导致数据库被更新。

I think it's better if the transaction is inside the loop.我认为如果事务在循环内会更好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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