[jboss-user] [EJB 3.0] - Re: Transaction annotation - cannot get desired behavior

amitka do-not-reply at jboss.com
Sun May 20 10:01:46 EDT 2007


One way to solve it, from my experience, would be to inject another instance of that bean to itself, and invoke the method (the one annotated with REQUIRES_NEW) on that injected bean. Otherwise the transaction attributes annotations have no effect because you're not working with the proxy but with the class itself.

i.e.

@Stateless public class YourBean impelemts YourBeanLocal {
  | 
  |   @EJB YourBeanLocal yourBean;
  | 
  |   public void callingMethod() {
  |     ...
  |     yourBean.yourRequiresNewMethod(...);
  |     ...
  |   }
  | 
  |   @TransactionAttribute(...REQUIRES_NEW) yourRequiresNewMethod() {
  |     ...
  |   }
  | }
  | 

This does have a problem that whenever using this bean you're actually acquiring 2 instances of it.

If you think of a better way to do it, I'll be very glad to know.

HTH.

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4047057#4047057

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4047057



More information about the jboss-user mailing list