PROPAGATION_REQUIRES_NEW starts a new, independent "inner" transaction for the given scope. This transaction will be committed or rolled back completely independent from the outer transaction, having its own isolation scope, its own set of locks, etc. The outer transaction will get suspended at t...
Cloud Studio代码运行 @Transactional(propagation=Propagation.REQUIRES_NEW,isolation=Isolation.READ_COMMITTED)publicvoidqueryUesr()throws Exception{query();thrownewRuntimeException();} 我们暂时先不要看方法上面的传播属性,因为我们要针对各种情况做详细的分析,我们暂时具体分析下面四种情况 1.第一个业务方法抛异常即...
REQUIRES_NEW:创建新的transaction并执行;如果当前已有transaction,则将当前transaction挂起; NOT_SUPPORTED:在无transaction状态下执行;如果当前已有transaction,则将当前transaction挂起; NEVER:在无transaction状态下执行;如果当前已有transaction,则抛出异常IllegalTransactionStateException。 二、REQUIRED与REQUIRED_NEW 上面描述的...
REQUIRES_NEW 当REQUIRES_NEW使用时,Spring暂停当前的Transaction,并创建一个新的。 我们看下代码怎么使用: 代码语言:javascript 代码运行次数:0 复制Cloud Studio 代码运行 @Transactional(propagation = Propagation.REQUIRES_NEW) public void deleteBookWithRequiresNew(Long id){ } 相应的实现代码如下: 代码语言:jav...
REQUIRES_NEW(3), NOT_SUPPORTED(4), NEVER(5), NESTED(6); private final int value; private Propagation(int value) { this.value = value; } public int value() { return this.value; } } 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. ...
REQUIRES_NEW:内部方法和外部方法不是同一个事物,内部方法抛出异常,外部不回滚,外部抛出异常,内部回滚。此处注意内部抛出异常,外部不处理,相当于外部直接往外抛。 NESTED:内外方法嵌套事物,内部抛出异常,外部不回滚,外部抛出异常,内部回滚。 注意:我们在开发的时候,一般我们使用默认的就行了,因为默认的是最安全的,只要...
REQUIRES_NEW 当REQUIRES_NEW使用时,Spring暂停当前的Transaction,并创建一个新的。 我们看下代码怎么使用: @Transactional(propagation=Propagation.REQUIRES_NEW)publicvoiddeleteBookWithRequiresNew(Longid){} 相应的实现代码如下: if(isExistingTransaction()){suspend(existing);try{returncreateNewTransaction();}catch...
Propagation.REQUIRES_NEW:重新创建一个新的事务,如果当前存在事务,暂停当前的事务。( 当类A中的 a 方法用默认Propagation.REQUIRED模式,类B中的 b方法加上采用 Propagation.REQUIRES_NEW模式,然后在 a 方法中调用 b方法操作数据库,然而 a方法抛出异常后,b方法并没有进行回滚,因为Propagation.REQUIRES_NEW会暂停 a方...
@Transactional(rollbackFor = Exception.class,propagation = Propagation.REQUIRES_NEW) public void addUser02(User user02) { userDao.insert(user02) ; } } 然后就开始带着大家看相关的源码,首先打断点会进入到如下的方法(你如果想尝试就在这个类【TransactionAspectSupport】的如下方法中打一个断点)。
方法一 required --- 方法二 requires_new 方法一 required --- 方法二 nested (当前存在事务 则嵌套在事务内执行,没有事务则新开启一个事务) 具体代码 主要集中在 AbstractPlatformTransactionManager 典型的模板方法的设计模式, 子类调用父类的 getTransaction(),这个方法时不能不能不重写的方法,子类只能重写里面...