what are the transaction attributes of methodA, methodB, and methodC respectively?

Given the following stateless session bean implementation classes:

Assuming no other transaction-related metadata, what are the transaction attributes of methodA,
methodB, and methodC respectively?

Given the following stateless session bean implementation classes:

Assuming no other transaction-related metadata, what are the transaction attributes of methodA,
methodB, and methodC respectively?

A.
MANDATORY, MANDATORY , and MANDATORY

B.
REQUIRED, MANDATORY, and REQUIRES_NEW

C.
MANDATORY, MANDATORY , and REQUIRES_NEW

D.
REQUIRED, REQUIRES_NEW, and REQUIRES_NEW

Explanation:
Note:
*You can only bring out the effects of transaction attributes only when you call the method through
a session bean instance and NOT through a direct method call. Even if your methods are within
the same bean, you need to get the local instance of the same bean and call through its local

interface instead of a direct method invoke.
*The enum TransactionAttributeType is used with the TransactionAttribute annotation to specify
whether the methods of a session bean or message driven bean are called with a valid transaction
context.
*MANDATORY
If a client invokes the enterprise bean’s method while the client is associated with a transaction
context, the container invokes the enterprise bean’s method in the client’s transaction context.
*REQUIRES_NEW
The container must invoke an enterprise bean method whose transaction attribute is set to
REQUIRES_NEW with a new transaction context.
Reference:TransactionAttributeType.MANDATORY



Leave a Reply 4

Your email address will not be published. Required fields are marked *


Figaro

Figaro

MyBean has default TransactionAttributeType.REQUIRED and it overrides transaction type MANDATORY, inherited from MySuper, for methodA. methodB has inherited MANDATORY and methodC has overriden REQUIRES_NEW.
So answer B is correct.

Mapi

Mapi

It’s B, because: “A method defined in a superclass but overridden in a child class (to the superclass) has the transaction attribute as defined in the child class, or the default transaction attribute of the child class.”