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 localinterface 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
B
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.
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.”
B