Results 1 to 6 of 6

Thread: Anyway to make an Advice transactional?

  1. #1

    Default 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. #2
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,629

    Default

    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...
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  3. #3

    Default

    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 at 08:19 AM.

  4. #4
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,629

    Default

    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.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  5. #5

    Default

    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

  6. #6
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,629

    Default

    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.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •