开发者

what will happened if i dont call transaction.close or transaction.rollback?

In the begin of the unit of work I call to session.BeginTransdaction I noticed that even if no changes where done to the DB during the transaction the commit is still expensive.

What will happen if in case of no changes I just call session.close and I开发者_Go百科 don't call transaction.commit? Does the transaction still dispose?


I have checked the sources of NHibernate 3.1.0 and it seems that calling the ISession.Close() should result in a ITransaction.Dispose() for the default implementation. But nevertheless using that in an existing application did not result in a explicit transaction commit or rollback - checked with the NHibernate Profiler.

I don't think it is a good idea to leave the transaction to rely only on the ISession.Close() as it can lead to unpredictable behaviors. What if someone will adapt that particular method and include the ISession.SaveOrUpdate... your entities will not get persisted.

UPDATE:

From the Sql Server perspective I think it depends on your transaction isolation level but I'm pretty sure that sooner or later you will encounter locks or timeouts. Please refer to this sql-server specific question:

What happens to an uncommitted transaction when the connection is closed?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜