Announcement Announcement Module
No announcement yet.
Rollback rules are a little ambiguous Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Rollback rules are a little ambiguous

    The documentation is a little ambiguous as to how rollback-for and no-rollback-for are applied. For example, I have MyBusinessException, and MyBusinessWarningException, which inherits from MyBusinessException. If I have rollback-for="MyBusinessException", and no-rollback-for="MyBusinessWarningException", what will happen when a MyBusinessWarningException is thrown? Will it be rolled back because its an instance of MyBusinessException, or will it be committed because its an instance of MyBusinessWarningException? Even if the behavior is undefined, and hence shouldn't be relied upon, I think this should be stated in the documentation.

  • #2
    In your case, I think the transaction will not rollback, because no-rollback-for rule is applied. Matching process considers the 'strongest' matching rule from list of rules.

    If the exception being thrown matches exactly the exception in one of your rules, then that rule is applied. In your case, for rollback-for="MyBusinessException" and MyBusinessWarningException being thrown, the matching process has to go up in the class hierarchy until reaches MyBusinessException and this is a 'weaker' matching rule than the one for no-rollback-for.
    Checkout the source code for org.springframework.transaction.interceptor.RuleBa sedTransactionAttribute class.

    If you think this should be documented, feel free to raise a JIRA issue.


    • #3
      Hi guys

      Andrei is correct... thank goodness Spring has such great members of the community, nice one Andrei. I'll sign off before this post gets too schmaltzy

      Oh! I've gone and updated the relevant section of the Spring reference documentation to be more explicit about the rollback rules as per your comment jroper2. (So there is no need to raise a JIRA issue.)



      • #4
        Thanks for the reply, and thanks for updating the documentation. I got myself a little confused in my own post, I meant the other way around, rollback-for="MyBusinessWarningException" and no-rollback-for="MyBusinessException", but, I get gist, in that case, the transaction will be rolled back.