Announcement Announcement Module
Collapse
No announcement yet.
AfterReturning - how to deal with Transactional Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • AfterReturning - how to deal with Transactional

    Hello,

    I was not sure where exactly to post my question since this kind of overlaps with data access, but I decided to post here as I think it's more AOP related.

    I have a pretty simple scenario:

    I have a @Transactional method somewhat like this:

    @Transactional(readOnly = false, rollbackFor = DataAccessException.class)
    public void saveDataTransaction(MyData data) {
    // do database work here... using JPA EntityManager, although it's not relevant
    ....
    }

    Then in my AfterReturning aspect, I have something like this:

    @AfterReturning("execution(* com...save*(..))")
    public void afterReturningSaveObject(JoinPoint jp) throws DataExportException {
    ....
    }


    Then my question is: is that GUARANTEED that my AfterReturning advice will only be called AFTER the transaction from method saveDataTransaction is COMMITTED? By what I have read so far, it is not, but wanted to get input and see if anyone has any suggestion on how to make sure transaction is always committed before getting into AfterReturning code.

    Thank you in advance.

  • #2
    Then my question is: is that GUARANTEED that my AfterReturning advice will only be called AFTER the transaction from method saveDataTransaction is COMMITTED? By what I have read so far, it is not, but wanted to get input and see if anyone has any suggestion on how to make sure transaction is always committed before getting into AfterReturning code.
    No... The order of advices can be specified in configuration and by @Order annotations. Without it it depends on your whole configuration. If you want to guarantee an order specify the order.

    Comment


    • #3
      Originally posted by Marten Deinum View Post
      No... The order of advices can be specified in configuration and by @Order annotations. Without it it depends on your whole configuration. If you want to guarantee an order specify the order.
      Thanks a lot Marten for your input, you confirmed my suspicion. I will explore the Order.

      Comment

      Working...
      X