eric-1001c

            BlogJava :: 首頁 :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理 ::
            3 隨筆 :: 45 文章 :: 12 評論 :: 0 Trackbacks
          Let me first of all state the expected behavior: Silently marking a transaction as rollback-only through a setRollbackOnly call will work as long as you do it at the *outermost* transaction level. If you do it within an inner transaction scope, the outer transaction will see this as a "global" rollback-only and throw an UnexpectedRollbackException - since the code in the outer transaction did not explicitly ask for a rollback, so needs to be notified.

          So in your scenario, I would assume that you do the setRollbackOnly within an inner transaction scope. Since you're using <tx:advice>, this could mean that your pointcut is too broad and applies transaction demarcation at multiple levels: for example, at the Controller level as well as at the service level, with the setRollbackOnly call happening in a service - this would lead to an UnexpectedRollbackException at the Controller level.

          That said, I would actually argue that you should virtually never be using a programmatic setRollbackOnly call in the first place, or more specifically, a rollback without exception thrown to the caller. This usually indicates inappropriate transaction scopes.

          In particular, web data binding should *not* happen within a transaction. Rather, perform data binding without transaction first, then start transactions at the service level *once you decided to process the bound data*, with the bound data brought into the transaction through a merge operation. This way, validation errors don't require a transaction rollback in the first place...

          Aside from avoiding programmatic setRollbackOnly calls in your application code, the above approach to validation and transactions also avoids excessive rollbacks in your transaction statistics. Such rollbacks for frequent and perfectly normal user interactions should in particular be avoided in administered environments like a J2EE server installation - with transaction monitoring and (potentially) escalation messages generated for rollbacks.
          posted on 2008-04-05 12:36 Eric-1001c 閱讀(211) 評論(0)  編輯  收藏 所屬分類: Hibernate
          主站蜘蛛池模板: 遂昌县| 九江县| 施甸县| 襄垣县| 望谟县| 祁门县| 禄丰县| 大石桥市| 双流县| 平邑县| 绥德县| 定安县| 淮滨县| 曲沃县| 桃源县| 明光市| 巴塘县| 安图县| 壤塘县| 乌兰察布市| 宁都县| 加查县| 龙岩市| 湄潭县| 扬州市| 龙川县| 贵州省| 大关县| 永胜县| 墨竹工卡县| 睢宁县| 岳西县| 淮阳县| 平度市| 鹤岗市| 双江| 南木林县| 东安县| 玉屏| 叙永县| 孙吴县|