Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Spring Aspects advices without transactions

 
Fernando Franzini
Ranch Hand
Posts: 489
2
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • 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.
 
Bill Gorder
Bartender
Posts: 1682
7
Android IntelliJ IDE Linux Mac OS X Spring
 
Fernando Franzini
Ranch Hand
Posts: 489
2
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • 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 IntelliJ IDE Linux Mac OS X Spring
  • Mark post as helpful
  • send pies
  • 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: 489
2
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • 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.
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • 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: 489
2
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • 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
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • 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: 489
2
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • 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 IntelliJ IDE Linux Mac OS X Spring
  • Mark post as helpful
  • send pies
  • 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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic