Spring事务传播机制

Spring有以下的事务机制:

/**
 * Support a current transaction, create a new one if none exists.
 */
REQUIRED(TransactionDefinition.PROPAGATION_REQUIRED),
支持当前的事务,如果当前没有事务,就创建一个事务,它也是默认的事务机制。


/**
 * Support a current transaction, execute non-transactionally if none exists.
 */
SUPPORTS(TransactionDefinition.PROPAGATION_SUPPORTS),
支持当前事务,如果不存在事务,则不执行事务。如果存在,则执行事务。

/**
 * Support a current transaction, throw an exception if none exists.
 */
MANDATORY(TransactionDefinition.PROPAGATION_MANDATORY),
强制要求当前必须存在事务,如果不存在事务,则抛出异常

/**
 * Create a new transaction, and suspend the current transaction if one exists.
 */
REQUIRES_NEW(TransactionDefinition.PROPAGATION_REQUIRES_NEW),
如果当前存在事务,则挂起该事务,并创建新一个新的事务。

/**
 * Execute non-transactionally, suspend the current transaction if one exists.
 */
NOT_SUPPORTED(TransactionDefinition.PROPAGATION_NOT_SUPPORTED),
如果当前存在事务,则挂起该事务。然后自身不使用事务

/**
 * Execute non-transactionally, throw an exception if a transaction exists.
 */
NEVER(TransactionDefinition.PROPAGATION_NEVER),
如果当前存在事务,则抛出异常,相当于强制性的不使用事务

/**
 * Execute within a nested transaction if a current transaction exists,
 * behave like {@code REQUIRED} otherwise. 
 */
NESTED(TransactionDefinition.PROPAGATION_NESTED);
如果当前存在事务,则创建一个嵌套的子事务。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值