繁体   English   中英

延迟加载和多个事务

[英]lazy loading and multiple transactions

我对一个休眠会话中的惰性迭代器和多个事务感到有些困惑。 有以下代码块:

@Transactional
public void runtProcessing() {
HibernateTemplate hibernateTemplate = ...
Session hibernateSession = hibernateTemplate.getSessionFactory().getCurrentSession();
Iterator<DomainObject> domainObjects = hibernateTemplate.iterate(...);
            try {
                while (domainObjects.hasNext()) {
                    hibernateSession.beginTransaction();
                    DomainObject domainObject = domainObjects.next();

                    processDomainObject(domainObject);
                    hibernateSession.getTransaction().commit();
                }
}

由于存在多个事务,所以我想知道迭代器在哪个事务中工作?

从这里http://ayende.com/blog/3775/nh-prof-alerts-use-of-implicit-transactions-is-discouraged

当我们不定义自己的事务时,我们将退回到隐式事务模式,在该模式下,数据库的每个语句都在其自己的事务中运行,从而导致更高的性能成本(建立和拆除事务的数据库时间)并降低了一致性。

因此,迭代器作为其自身事务的一部分运行。 希望有道理。

暂无
暂无

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

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