但笔者今天不讨论这个,哈哈~本文将从应用层面稍带一点源码,来解释一下我们平时使用事务遇到的一个问题但让很多人又很棘手的问题:Transaction rolled back because it has...: Transaction rolled back because it has been marked as rollback-only 但这么玩,去掉addPerson方法的事务,只保留editById...rolled back because it has been marked as rollback-only"); } } finally { cleanupAfterCompletion...**如果这个子方法没有将异常往上整个方法抛出或整个方法未往上抛出,那么改异常就不会触发事务进行回滚,事务就会在整个方法执行完后就会提交,这时就会造成Transaction rolled back because...it has been marked as rollback-only的异常。
* The completed flag has already been checked....rolled back because it has been marked as rollback-only"); } } finally { cleanupAfterCompletion...back because it has been marked as rollback-only"); } } catch (UnexpectedRollbackException...silently rolled back because it has been marked as rollback-only);这里是status.isGlobalRollbackOnly()被标记为...silently rolled back because it has been marked as rollback-only)。
}else {// We don't roll back on this exception.// Will still roll back if TransactionStatus.isRollbackOnly...rolled back because it has been marked as rollback-only");}}finally {cleanupAfterCompletion(status);...back because it has been marked as rollback-only");}}catch (UnexpectedRollbackException ex) {// can...silently rolled back because it has been marked as rollback-only);这里是status.isGlobalRollbackOnly()被标记为...silently rolled back because it has been marked as rollback-only)。
If the transaction * has been marked rollback-only programmatically, perform a rollback....If a previous transaction * has been suspended to be able to create a new one, resume the previous...* is already completed (that is, committed or rolled back) * @see TransactionStatus#setRollbackOnly...If a previous transaction * has been suspended to be able to create a new one, resume the previous...* is already completed (that is, committed or rolled back) */ void rollback(TransactionStatus status
如果使用不慎, 会引发 org.springframework.transaction.UnexpectedRollbackException: Transaction rolled back because...it has been marked as rollback-only ---- 具体原因见以下demo简例: 部分关键代码 DemoService1 public class DemoService1Impl...*/ @Override @Transactional(propagation = Propagation.REQUIRED,rollbackFor = Exception.class...: Transaction rolled back because it has been marked as rollback-only at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit...rolled back because it has been marked as rollback-only
If step 4 fails and rolls back TXN2, then TXN1 will not roll back because it has already been committed...and can guarantee it has been delivered....message has been successfully sent....Each batch is submitted immediately after the previous one has been successfully submitted....rolled back.
*/int STATUS_ROLLED_BACK = 1;/** Completion status in case of heuristic mixed completion or system errors...Can perform further operations right * after the main transaction has successfully committed...cleanup after transaction completion. * NOTE: The transaction will have been committed...or rolled back already, * but the transactional resources might still be active and accessible....* @see #STATUS_COMMITTED * @see #STATUS_ROLLED_BACK * @see #STATUS_UNKNOWN * @see #beforeCompletion *
commit. */ int STATUS_COMMITTED = 0; /** Completion status in case of proper rollback. */ int STATUS_ROLLED_BACK...Can perform further operations right * after the main transaction has successfully committed...* NOTE: The transaction will have been committed or rolled back already, * but the transactional...* @see #STATUS_COMMITTED * @see #STATUS_ROLLED_BACK * @see #STATUS_UNKNOWN * @see #beforeCompletion...int) * @see TransactionSynchronization#STATUS_COMMITTED * @see TransactionSynchronization#STATUS_ROLLED_BACK
* branch has been committed, or be discarded if local transaction has been rolled back...* * @throws OMSRuntimeException if the instance has not been suspended....} to go back and forth...has no previous message, or * the the consumer fails to receive the previous message */...iteration has no previous message */ String previousPosition(); } 是一个read-only的iterator,类似java
manager has been configured"); } } } //2.构建事务信息 return prepareTransactionInfo(tm, txAttr...throw ex; } //扩展点 triggerAfterCompletion(status, TransactionSynchronization.STATUS_ROLLED_BACK...rolled back because it has been marked as rollback-only"); } } finally { //清理资源 cleanupAfterCompletion...back because it has been marked as rollback-only"); } } catch (UnexpectedRollbackException...can only be caused by doCommit triggerAfterCompletion(status, TransactionSynchronization.STATUS_ROLLED_BACK
Material Ledger Actual Costing has been activated already in the system before the system conversion...Description With S/4HANA the data model for material ledger data has been changed significantly, especially...'old' data has not been converted to the MLDOC-tables....To show data older than last period of previous year you can use transaction CKM3OLD('Material Price...The section Costing Results has been removed.
public class ServiceB{ @Transactional(rollbackFor = Exception.class) public void methodB(){...异常信息: Transaction rolled back because it has been marked as rollback-only 2 异常原因追溯 由于methodB方法抛出异常导致事务已经回滚...originator decide on rollback"); } } } else { logger.debug("Should roll back transaction...TransactionSynchronization.STATUS_UNKNOWN); throw ex; } triggerAfterCompletion(status, TransactionSynchronization.STATUS_ROLLED_BACK...rolled back because it has been marked as rollback-only"); } }finally { cleanupAfterCompletion
前言 最近在项目中发现了一则报错:“org.springframework.transaction.UnexpectedRollbackException: Transaction rolled back...because it has been marked as rollback-only”。...: Transaction rolled back because it has been marked as rollback-only”。...ServiceB b; @Transactional public void a() { try { b.b() } catch (Exception...附:事务传播方式 @see org.springframework.transaction.annotation.Propagation 事务传播方式 说明 PROPAGATION_REQUIRED
前言 最近在项目中发现了一则报错:“org.springframework.transaction.UnexpectedRollbackException: Transaction rolled back...because it has been marked as rollback-only”。...: Transaction rolled back because it has been marked as rollback-only”。...ServiceB b; @Transactional public void a() { try { b.b() } catch (Exception...附:事务传播方式 @see org.springframework.transaction.annotation.Propagation 事务传播方式 说明 PROPAGATION_REQUIRED 如果当前没有事务
Can perform further operations right * after the main transaction has successfully committed...* NOTE: The transaction will have been committed already, but the * transactional resources...if (unexpectedRollback) { throw new UnexpectedRollbackException( "Transaction silently rolled...back because it has been marked as rollback-only"); } } catch (UnexpectedRollbackException...can only be caused by doCommit triggerAfterCompletion(status, TransactionSynchronization.STATUS_ROLLED_BACK
Can perform further operations right * after the main transaction has successfully committed..., like confirmation messages or emails. * NOTE: The transaction will have been committed already...from commit.if (unexpectedRollback) {throw new UnexpectedRollbackException("Transaction silently rolled...back because it has been marked as rollback-only");}}catch (UnexpectedRollbackException ex) {// can...only be caused by doCommittriggerAfterCompletion(status, TransactionSynchronization.STATUS_ROLLED_BACK
note) { // 一系列 DB 操作 try { searchService.sync(note); } catch (Exception...entity.setCategory("苏轼诗词"); try { noteService.save(entity); } catch (Exception...[XXX] // FIXME 但是这里拿到的是 Transaction silently rolled back because it has been marked as rollback-only...3、事务提交时,进行事务状态的判断,就发现这个事务是失败的,需要回滚,所以抛出了 Transaction silently rolled back because it has been marked
// We don't roll back on this exception. // Will still roll back if TransactionStatus.isRollbackOnly...throw ex; } triggerAfterCompletion(status, TransactionSynchronization.STATUS_ROLLED_BACK...rolled back because it has been marked as rollback-only"); } } finally { //...silently rolled back because it has been marked as rollback-only"); } }...be caused by doCommit triggerAfterCompletion(status, TransactionSynchronization.STATUS_ROLLED_BACK
领取专属 10元无门槛券
手把手带您无忧上云