Announcement Announcement Module
Collapse
No announcement yet.
Anyway to make an Advice transactional? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Anyway to make an Advice transactional?

    Hi,

    Is there anyway to make and advice transactional? Ideally, I'd like to be able to use @Transactional annotations, but the spring docs http://static.springsource.org/sprin...aop-at-aspectj indicate:

    "In Spring AOP, it is not possible to have aspects themselves be the target of advice from other aspects. The @Aspect annotation on a class marks it as an aspect, and hence excludes it from auto-proxying."

    That would also imply an xml configuration (non-annotated) would not help either.

    Am I misunderstanding the docs? Is there a way to make and advice transactional?

    Thanks,

    Eric

  • #2
    What is your use case here? Not sure what (or why you want it). Basically if you want it to be transactional (or let it participate in the ongoing transaction) make sure it executes AFTER the transactional advice, that is where the order attribute comes in handy...

    Comment


    • #3
      Actually, I'm looking to make it independently transactional. If it ends up being part of a larger transaction, great. But don't want to count on it.

      Basically, I have an advice that is intercepting values at a controller level before they get passed on to the services. The goal is to modify the incoming values transparently to the services; they need not know that the values have been altered. The problem is that at times, some of the value changes must come from the db and so a read/write call is required at the advice level. Not all services that use these values are necessarily transactional.

      Consequently, I was looking to see if there was a way to make the advice transactional so I know that when it fires it could do its necessary read-writes without being dependent on any other open transactions.

      Is there anyway to code/configure it to be as such?

      Thanks,

      Eric
      Last edited by benze; Jul 24th, 2011, 09:19 AM.

      Comment


      • #4
        As you already noticed @Transactional (or any other means of declarative transaction management) isn't going to work (at least not if you want to be in control, I would simply make it part of another transaction). YOu will have to do programmatic transaction management, so you probably want to inject/construct a TransactionTemplate into your aspect and use it in there.

        Comment


        • #5
          Any suggestions where I might be able to find an example of the use of TransactionTemplate? I tried to take a quick look at TransactionInterceptor, but quite frankly, not able to understand it as clearly as I would have hoped. Any ideas where I might be able to find other examples of how to use it?

          Thanks,

          Eric

          Comment


          • #6
            I suggest a read of the transaction chapter in the reference guide, the use of TransactionTemplate (or programmatic transaction management) is also explained in there.

            Comment

            Working...
            X