0
我对一个休眠会话中的惰性迭代器和多个事务有点困惑。有以下代码块:延迟加载和多个事务
@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();
}
}
由于有多个事务,我不知道迭代器在什么事务中工作?
用'@ Transactional'注释更新代码。已经有一个打开的交易。 –