*
The moose likes Spring and the fly likes Spring Aspects advices without transactions Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "Spring Aspects advices without transactions" Watch "Spring Aspects advices without transactions" New topic
Forums: Spring Aspect Oriented Programming
Author

Spring Aspects advices without transactions

Fernando Franzini
Ranch Hand

Joined: Jan 09, 2009
Posts: 486
    
    2

Hello Folks
I'm using bean1 with @AfterReturning to make a proxy for a existing bean2 that implements an transactional processing, Bean2 is using @Transactional. The problem is the bean1 proxy method with @AfterReturning is running within a transaction that target bean1 and I would like to execute proxy method outside the target bean1 transaction.
I already searched but did not find how to do this. Anyone know how to do it?
Best Regards.


Fernando Franzini - Java Blog
Bill Gorder
Bartender

Joined: Mar 07, 2010
Posts: 1648
    
    7



http://static.springsource.org/spring/docs/3.2.2.RELEASE/spring-framework-reference/htmlsingle/#tx-propagation-requires_new


[How To Ask Questions][Read before you PM me]
Fernando Franzini
Ranch Hand

Joined: Jan 09, 2009
Posts: 486
    
    2

Propagation.REQUIRES_NEW will open new transaction...
The idea is to run with no transaction.
Bill Gorder
Bartender

Joined: Mar 07, 2010
Posts: 1648
    
    7

would like to execute proxy method outside the target bean1 transaction.

Sorry I misunderstood what you said I thought what you wanted is a new transaction.

You have not shown us any code so its hard to help to much.

Perhaps you are looking to apply ordering to your advice? See this link in the reference documentation:
http://static.springsource.org/spring/docs/3.2.2.RELEASE/spring-framework-reference/htmlsingle/#aop-ataspectj-advice-ordering
Fernando Franzini
Ranch Hand

Joined: Jan 09, 2009
Posts: 486
    
    2

Hello Bill

Here are the code:

This is bean2 that implements a transactional processing:

This is bean1 used to add advice bean2


The problem is that the bean1 used to add advice to bean2 is running within the transaction bean2.finalizar(). What I need is the bean1 execute with no transactional context. How to do this?
Very strange because I thought the advice would not enter into the transaction bean2.finalizar().
i appreciate any help!
Best Regard.
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

Wouldn't you just use Propagation.NOT_SUPPORTED.

That way that advice method will not run in a transaction.

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Fernando Franzini
Ranch Hand

Joined: Jan 09, 2009
Posts: 486
    
    2

Mark Spritzler wrote:Wouldn't you just use Propagation.NOT_SUPPORTED.
That way that advice method will not run in a transaction.
Mark

I think the spring will suspend the transaction for both beans. I'll try here ...
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

Fernando Franzini wrote:
Mark Spritzler wrote:Wouldn't you just use Propagation.NOT_SUPPORTED.
That way that advice method will not run in a transaction.
Mark

I think the spring will suspend the transaction for both beans. I'll try here ...


Yes the calling Transaction will be suspended.

Mark
Fernando Franzini
Ranch Hand

Joined: Jan 09, 2009
Posts: 486
    
    2

Propagation.NOT_SUPPORTED not work!
Actually it suspends all transactions which are called inside the bean advice.
Only option left to me is to make a GOF Decorator manually. I test and it works correctly .. but it is very bad to do manual ...
Regards.
Bill Gorder
Bartender

Joined: Mar 07, 2010
Posts: 1648
    
    7

Once again try ordering your aspects. You want the after returning aspect of the @Transactional to complete before yours. If you read the link I gave above, the higher precedence will run first going in and last going out. Since @Transactional runs with Ordered.LOWEST_PRECEDENCE by default you could up that value a little by providing it in the @EnableTransactionMnaagent parameters or alternatively on the <tx:annotation-driven/> tag if you are using XML. Then provide an @Order annotation defining a lower precedence to your aspect than what you have defined on the transaction stuff. Note the @Order tag only has an effect if you are using Springs proxy based AOP of you are not using that you need to take a slightly different approach. Have a look at the link below in that case.

i,e.


Then on your aspect add



http://forum.springsource.org/showthread.php?85082-Aspect-Order
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Spring Aspects advices without transactions
 
Similar Threads
transaction in EJB 2
Transaction Doubt
Spring Aspect Question
JTA @transaction not commited
Methods on advice are not being called