Spring框架学习[Spring具体事务处理器的实现](三)

2014-11-24 03:00:34 · 作者: · 浏览: 22
//获取Hibernate事务对象 HibernateTransactionObject txObject = (HibernateTransactionObject) status.getTransaction(); if (status.isDebug()) { logger.debug("Rolling back Hibernate transaction on Session ["+SessionFactoryUtils.toString(txObject.getSessionHolder().getSession()) + "]"); } try { //通过Hibernate事务执行回滚操作 txObject.getSessionHolder().getTransaction().rollback(); } catch (org.hibernate.TransactionException ex) { throw new TransactionSystemException("Could not roll back Hibernate transaction", ex); } catch (HibernateException ex) { throw convertHibernateAccessException(ex); } finally { if (!txObject.isNewSession() && !this.hibernateManagedSession) { //清除事务对象中的Hibernate Session txObject.getSessionHolder().getSession().clear(); } } }…… }

通过上面对Hibernate事务处理器的分析,我们看到真正执行提交、回滚等事务操作的还是Hibernate Transaction事务对象,这与单独直接使用Hibernate没有什么区别,只是Spring将其做了通用封装,更加方便使用。