[jboss-user] [EJB/JBoss] - Re: transaction propagation

asookazian do-not-reply at jboss.com
Mon Mar 23 18:29:18 EDT 2009


here is a reply from Ken Saks, spec lead of JSR 318:
anonymous wrote : 
  | On Mar 23, 2009, at 4:26 PM, Arbi.Sookazian at cox.com wrote:
  | 
  | 
  | Hello,
  | 
  | I would like to draw attention to this specific part of JSR 318, proposed final draft dated Feb 24, 2009, which is the same as in JSR 220, section 13.3.7.1:
  | 
  | Specifying the TransactionAttribute annotation on the bean class means that it applies to all applicable business interface methods of the class.
  | 
  | 
  | 
  | In EJB 3.1 (or later), I'm wondering if it will be possible to demarcate transaction attribute value (e.g. REQUIRED, REQUIRES_NEW, etc.) on private, protected, or package-private in a SFSB or SLSB (i.e. any method with less than public visibility).  The current behavior in EJB 3.0 seems to be that the EJB container (in my case JBoss AS) ignores the transaction demarcation annotation on a private method and there is no warning from Eclipse, or exception/warning during deployment or runtime exception.  
  | 
  | I ran into this problem recently and it took me over *two days* to determine the root cause of the behavior in terms of transaction semantics and CMT in my SFSB.  My workaround to this problem was to refactor the private method to a public method defined in the local interface implemented by a new SFSB.  The REQUIRES_NEW transaction demarcation for the public method in the new SFSB is now honored by the ejb container.  
  | 
  | Why is it necessary to do this?  We should be able to demarcate non-local interface methods or non-remote interface methods with transaction demarcation when using CMT.
  | 
  | 
  | 
  | Hi Arbi,
  | 
  | 
  | The behavior you're seeing is not specific to transaction attributes.  All the special semantics associated with an EJB component invocation (method authorization, container exception handling, threading guarantees, container-managed transactions, etc.) only apply to invocations made through an EJB reference.  When code already running within a business method invocation calls another method on the same class through the "this" pointer, the EJB container isn't involved.  Such a method invocation is just a plain Java SE method call.  
  | 
  | 
  | If you want to invoke a business method on your bean from another business method on the same bean, you'll need to acquire an EJB reference to yourself.  The easiest way is to call SessionContext.getBusinessObject().  
  | 
  | 
  | 
  | 
  | TestTransactionsLocal ejbRefToMyself =  sessionCtx.getBusinessObject(TestTransactionsLocal.class)
  | ejbRefToMyself.otherMethod();
  | 
  | 
  | Regards,
  | 
  | 
  | Ken
  | 

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

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



More information about the jboss-user mailing list