<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    隨筆 - 100  文章 - 50  trackbacks - 0
    <2014年12月>
    30123456
    78910111213
    14151617181920
    21222324252627
    28293031123
    45678910

    常用鏈接

    留言簿(3)

    隨筆分類

    隨筆檔案

    文章分類

    文章檔案

    收藏夾

    我收藏的一些文章!

    搜索

    •  

    最新評論

    閱讀排行榜

    評論排行榜

    框架采用的是spring管理聲明式事務,這幾天業務開發時遇到了點麻煩,記錄下備忘。

     

     場景:在Service類中使用子事務(saveponit)時,當子事務拋出異常后,此異常處理掉不繼續往外拋,spring在提交主事務時會拋出

    org.springframework.transaction.UnexpectedRollbackException: Transaction has been rolled back because it has been marked as rollback

     

     方法調用結構:

          假若有A、B、C三個Service類,其實例對象分別為a、b、c,類分別定義如下:

     

                A {

                        方法() {                   //propagation="REQUIRED"

      try{

     

                                    b.方法();

       } catch (Exception e) {

               }

                        }      

       }

     

                B{

                         savePoint方法() {  //propagation="NESTED"

       c.方法(); //如果這里邊的操作全是普通類(不是Service類)操作,不會有問題。

                         }

                 }

     

     

                C{

                          方法() {                 //propagation="REQUIRED"

      throw new Exception("出錯");

         }

     

                  }

     

     

       通過調試spring源碼 

               ......

               Getting transaction for [A.方法] .....

               ......

       Creating nested transaction with name [B.savePoint方法]........

       ......

               Participating in existing transaction

               Getting transaction for [C.方法]

               ........

       Participating transaction failed - marking existing transaction as rollback-only

               //此時,已把主事務標記成了rollback-only

     

               所以,當在a.方法完成時提交事務時會報Transaction has been rolled back because it has been marked as rollback錯誤。

     

               認真的您可能會發現,在 org.springframework.transaction.support.AbstractPlatformTransactionManager 中有個叫

    isGlobalRollbackOnParticipationFailure的參數,默認是true.

     

              源碼中說明:

     

            Switch this to "false" to let the transaction originator make the rollback decision. If a participating transaction fails with an exception, the caller can still decide to continue with a different path within the transaction. However, note that this will only work as long as all participating resources are capable of continuing towards a transaction commit even after a data access failure: This is generally not the case for a Hibernate Session, for example; neither is it for a sequence of JDBC insert/update/delete operations.

     

              大意是:如果isGlobalRollbackOnParticipationFailure為false,則會讓主事務決定回滾,如果當遇到exception加入事務失敗時,調用者能繼續在事務內決定是回滾還是繼續。然而,要注意是那樣做僅僅適用于在數據訪問失敗的情況下且只要所有操作事務能提交。

     

            

        初步解決方案:

    <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <property name="dataSource" ref="dataSource" /> <property name="globalRollbackOnParticipationFailure" value="false" /> <!--指定此參數為false-->

    </bean>

     

     

        經測試,此問題暫時得到解決,不知道會不會引起其它問題,至少目前還沒有發現其它異常。您若通過此方案解決之后出現了新的問題請留信回復,我們一起交流,非常感謝!

     

    posted on 2014-12-20 14:23 fly 閱讀(598) 評論(0)  編輯  收藏 所屬分類: J2EE
    主站蜘蛛池模板: 亚洲五月综合网色九月色| 亚洲AV午夜福利精品一区二区 | 国产成人免费ā片在线观看老同学 | 91精品全国免费观看青青| 国产亚洲AV手机在线观看| 一个人看的在线免费视频| 久久久久亚洲AV成人网人人软件| 人人公开免费超级碰碰碰视频| 亚洲国产精品无码久久九九| sss日本免费完整版在线观看| 亚洲日韩精品无码专区网站| 中国一级毛片免费看视频| 亚洲国产精品成人精品无码区| 久久久国产精品福利免费| 亚洲黄色在线网站| 亚洲人成网站免费播放| 激情小说亚洲图片| 亚洲爽爽一区二区三区| 无码精品一区二区三区免费视频| 亚洲成aⅴ人在线观看| 全免费一级午夜毛片| 免费播放美女一级毛片| 国产精品亚洲片在线观看不卡| 亚洲免费在线视频| 亚洲影院天堂中文av色| 亚洲欧洲中文日韩av乱码| 香港a毛片免费观看 | 1区2区3区产品乱码免费| 亚洲国产成人精品无码区二本| 亚洲精品成人片在线观看| 免费A级毛片无码A∨| 亚洲午夜精品久久久久久app | 国产亚洲精品免费视频播放| 亚洲最大在线视频| 日韩精品电影一区亚洲| 日本在线免费播放| 久久亚洲中文无码咪咪爱| 亚洲国产a∨无码中文777| 国产网站在线免费观看| 嫩草在线视频www免费观看| 亚洲精品又粗又大又爽A片|