• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Spring Aspects advices without transactions

 
Ranch Hand
Posts: 497
2
Spring Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Bartender
Posts: 1682
7
Android Mac OS X IntelliJ IDE Spring Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


http://static.springsource.org/spring/docs/3.2.2.RELEASE/spring-framework-reference/htmlsingle/#tx-propagation-requires_new
 
Fernando Franzini
Ranch Hand
Posts: 497
2
Spring Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Propagation.REQUIRES_NEW will open new transaction...
The idea is to run with no transaction.
 
Bill Gorder
Bartender
Posts: 1682
7
Android Mac OS X IntelliJ IDE Spring Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 497
2
Spring Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Wouldn't you just use Propagation.NOT_SUPPORTED.

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

Mark
 
Fernando Franzini
Ranch Hand
Posts: 497
2
Spring Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 497
2
Spring Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 1682
7
Android Mac OS X IntelliJ IDE Spring Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic