spring 事务传播机制总结

spring事务的传播机制定义在 TransactionDefinition 接口中,定义了如下传播类型

PROPAGATION_REQUIRED

支持当前事务,如果没有当前事务就创建一个新的事务,是默认的传播行为。

外围方法未开启事务

内部会创建新事务,若新事务回滚,不影响外围方法。

外围方法开启事务

内部方法会加入到外围方法的事务中,使用同一个事务,不管内外谁发生异常,整个事务都将回滚。

/**
	 * Support a current transaction; create a new one if none exists.
	 * Analogous to the EJB transaction attribute of the same name.
	 * <p>This is typically the default setting of a transaction definition,
	 * and typically defines a transaction synchronization scope.
	 */
	int PROPAGATION_REQUIRED = 0;

PROPAGATION_SUPPORTS

支持当前事务,如果没有事务就以非事务方式执行。

外围方法未开启事务

以非事务方法运行。

外围方法开启事务

内部方法会加入到外围方法的事务中,使用同一个事务,不管内外谁发生异常,整个事务都将回滚。

    /**
	 * Support a current transaction; execute non-transactionally if none exists.
	 * Analogous to the EJB transaction attribute of the same name.
	 * <p><b>NOTE:</b> For transaction managers with transaction synchronization,
	 * {@code PROPAGATION_SUPPORTS} is slightly different from no transaction
	 * at all, as it defines a transaction scope that synchronization might apply to.
	 * As a consequence, the same resources (a JDBC {@code Connection}, a
	 * Hibernate {@code Session}, etc) will be shared for the entire specified
	 * sc
  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值