事務不起作用 Closing non transactional SqlSession


In proxy mode (which is the default), only external method calls coming in through the proxy are intercepted. This means that self-invocation, in effect, a method within the target object calling another method of the target object, will not lead to an actual transaction at runtime even if the invoked method is marked with  @Transactional.

 

spring文檔地址 :

http://docs.spring.io/spring/docs/4.2.0.RC1/spring-framework-reference/htmlsingle/#transaction-declarative-annotations

說明: 代理模式中,只攔截外部方法調用,開啟事務。類內部調用無法實現事務控制。

錯誤示例:

public class Tx {
    
    public void a(){
        b();
    }
    
    @Transactional(propagation = Propagation.REQUIRED)
    public void b(){
        
    }

}

 

正確示例:

public class Tx {
    
    @Transactional(propagation = Propagation.REQUIRED)
    public void a(){
        b();
    }
    
    
    public void b(){
        
    }

}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM