View Full Version : Transaction Proxy and "this"
dressina
08-10-2007, 02:58 AM
Hi,
We have noticed that method calls within a class instance (that are defined with transaction attributes in spring config) do not cause transactions to be initiated or enrolled. Method calls into a spring injected bean always cause transactions to be started or enlisted.
Is that the correct behavior? In other words, do calls to "this" NOT go through the Spring proxy?
Thanks,
Aaron
dressina
08-10-2007, 03:03 AM
You know... it really seems obvious that the answer is "yes"... and I see it in the debugger... not sure why I was a bit stumped when I did not see txs start up.
Please disregard unless someone has any input ;-P
Thanks,
Aaron
Mark Pollack
08-10-2007, 07:01 AM
Hi Aaron,
Call to 'this' inside a method that has AOP advice applied to it are not 'advised'. We plan to address this, if possible, in a 1.2 release. In the meantime there are a couple options. 1) Design around it. 2) Get a reference to the current AOP proxy, via AopContext.CurrentProxy and 3) add a method called This() to your class that literally returns this. You can then use method replacement features of spring to replace the implementation of This() with a call to AopContext.CurrentProxy. (This is a nice suggestion by Mike Plavsky in another thread (http://forum.springframework.net/showthread.php?t=3030)). I have not tried 3) but it is attractive because you don't couple the class to spring with the use of AopContext.CurrentProxy calls - if that matters to you. As a side note, it is certainly possible to design around it, Java EJB based systems have this same issue and are used for quite serious tx processing.
Cheers,
Mark
dressina
08-11-2007, 06:04 PM
thanks Mark!
Bruno Baia
08-21-2007, 09:43 AM
Hi,
Mike Plavsky's solution (http://forum.springframework.net/showthread.php?t=3030) is now working since 1.1 RC1.
I've uploaded an example to the wiki's forum question (http://opensource.atlassian.com/confluence/spring/display/NET/Forum+Questions) page based on the Spring.AopQuickStart sample:
Thread 3030 - Proxying 'this' with Spring.Aop and method injection
Bruno
vBulletin® v3.7.3, Copyright ©2000-2008, Jelsoft Enterprises Ltd.