Does criteria.List(Type) transaction management

妖精的绣舞 提交于 2019-12-11 04:28:52

问题


Does this (not CRUD, but only Read) code require me to write transaction management?

ICriteria criteria = SessionFactory.GetCurrentSession().CreateCriteria(EntityType);
criteria.List<BaseEntity>();

回答1:


I cannot say that I do it always, But I would say that this question is pretty reasonable. As you can Transactions for read-only DB access? what we can get is:

Transaction are required for read-only operations if you want to set a specific timeout for queries other than the default timeout, or if you want to change the isolation level.

And as mentioned here: NHibernate Transactions on Reads (small extract)

Even if we are only reading data, we want to use a transaction, because using a transaction ensure that we get a consistent result from the database.

So, in general, if you have common way (e.g. Web request handling with AOP) it could be useful




回答2:


No, why would you need a transaction for read only operations?

Transactions are only needed if you want to rollback multiple write/update/delete operations.



来源:https://stackoverflow.com/questions/20679126/does-criteria-listtype-transaction-management

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!