Jul 23rd, 2011, 09:50 PM
Anyway to make an Advice transactional?
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?
Jul 24th, 2011, 04:21 AM
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...
Jul 24th, 2011, 08:16 AM
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?
Last edited by benze; Jul 24th, 2011 at 08:19 AM.
Jul 24th, 2011, 12:47 PM
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.
Jul 24th, 2011, 11:46 PM
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?
Jul 25th, 2011, 02:15 AM
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.
Tags for this Thread