0
votes

This question is for my academic purpose only. Any response will be highly appreciated

Suppose i have a MDB with EJB TransactionAttribute.NOT_SUPPORTED.

@TransactionManagement(TransactionManagementType.BEAN)
@MessageDriven(name = "NonPersistentInquiryMessageBean", activationConfig = {    @ActivationConfigProperty(propertyName = "destinationType", propertyValue =          "javax.jms.Queue") })

public class InvoiceInquiryMessageBean implements MessageListener
{
 @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
 public void onMessage(Message msg) {

//calls a SSB-1 as defined below
//SSB-1.method1() 
 }
}

 @Stateless
 public class SSB-1 implements SSB-1Local
 {
   public void method1(){
 }

Question #1. AS i specified NOT_SUPPORTED for onMessage(), container executes the onMessage() without any transaction . When the SSB-1.method1() is invoked from onMessage() , will the container still execute the SSB-1.method1() without any transaction?(as per its definition)

Question #2 If i want the SSB-1.method1 to execute without a transaction should i explicitly mentioned NOT_SUPPORTED for the SSB-1 at the bean or method1() level? or just leave it as it is as the calling OnMessage() is already declared to be NOT_SUPPORTED

Question #3 Assuming the SSS-1.method1() is calling another SSB-2 for which i need to manage transaction, will the definition below work.

 @Stateless
 public class SSB-1 implements SSB-1Local
 {
   public void method1(){
            //call SSB-2.somemethod();
 }     

  @Stateless
  @TransactionManagement(TransactionManagementType.BEAN)
 public class SSB-2 
 {
   @Resource
   private UserTransaction userTransaction;
   public void somemethod(){
        userTransaction.begin();
        //biz logic
        userTransaction.commit()            
 }  
1

1 Answers

1
votes

[You need to look into naming conventions, it might be for demonstration, but still could have posted with better ones]

Question #1. AS i specified NOT_SUPPORTED for onMessage(), container executes the onMessage() without any transaction . When the SSB-1.method1() is invoked from onMessage() , will the container still execute the SSB-1.method1() without any transaction?(as per its definition)

No, that depends on the transaction attribute of SSB-1.method1(), if none specified then by default its Required & new transaction will be initiated as onMessage() didn't have any ongoing transaction.

Question #2 If i want the SSB-1.method1 to execute without a transaction should i explicitly mentioned NOT_SUPPORTED for the SSB-1 at the bean or method1() level? or just leave it as it is as the calling OnMessage() is already declared to be NOT_SUPPORTED

Need to explicitly mention SSB-1.method1(), same explanation as #1. Preferrably at method level to not enforce it on other class methods.

Question #3 Assuming the SSS-1.method1() is calling another SSB-2 for which i need to manage transaction, will the definition below work.

A CMT bean can accept transaction initiated by CMT & BMT, but reverse isn't true. BMT will suspend transaction & always creates new on its own. Based on your sample code, it won't work, SSB-1 is CMT while SSB-2 is BMT.