Spring的TransactionManger只有在捕获到RuntimeException或其子类才会自动回滚事务。
不知道你的getHibernateTemplate(true)做了什么,但我认为,这个方法抛出HibernateException是很可笑的事情。Spring的HibernateTemplate所有方法都是抛出DataAccessException,它是RuntimeException的子类。
不知道你的getHibernateTemplate(true)做了什么,但我认为,这个方法抛出HibernateException是很可笑的事情。Spring的HibernateTemplate所有方法都是抛出DataAccessException,它是RuntimeException的子类。
。如果我们希望服务方法一直在事务中运行,就可以使用PROPAGATION_REQUIRED。我们使用PROPAGATION_REQUIRED的时候,如果某个TX已经在运行中,那么bean方法加入那个TX,否则Spring轻量级TX管理器将为你重新启动一个
而这:
this.getHibernateTemplate(true).save(tcs);//(把true去掉也一样有问题)事务已经提交成功
this.getHibernateTemplate(true).save(tcs);//失败
两个save 应该不在一个事务里