Given the following stateless session bean implementation classes:
Assuming no other transaction-related metadata, what are the transaction attributes on methodB, and methodC respectively?
A.
MANDATORY, MANDATORY, and MANDATORY
B.
REQUIRED, MANDATORY, andREQUIRES_NEW
C.
MANDATORY, MANDATORY, <and REQUIRES__NEW
D.
REQUIRED, REQUIRES_NEW, and REQUIRES_NEW
the answer is correct, please check >>>
http://stackoverflow.com/questions/5536583/the-mystery-of-java-ee-6-annotations-inheritance
For details
Answer is correct:
methodB (REQUIRED) The Required attribute is the implicit transaction attribute for all enterprise bean methods running with container-managed transaction demarcation.
methodC (REGUIRES_NEW) RequiresNew is explicitly set.
I forgot to mention methodA(), so I will repeat my answer.
methodA (TransactionAttribute.REQUIRED): The Required attribute is the implicit transaction attribute for all enterprise bean methods running with container-managed transaction demarcation. It overrides TransactionAttribute which was set up on the MySuper superclass level.
methodB(TransactionAttribute.MANDATORY): It is explicitly set on the MySuper class level.
methodC (TransactionAttribute.REGUIRES_NEW) RequiresNew is explicitly set on method.
EJB 3.1 specification explanation:
A transaction attribute may be specified on a method of the bean class to override the transaction attribute value explicitly or implicitly specified on the bean class.
If the bean class has superclasses, the following additional rules apply.
• A transaction attribute specified on a superclass S applies to the business methods
defined by S. If a class-level transaction attribute is not specified on S, it is
equivalent to specification of TransactionAttribute(REQUIRED) on S.
• A transaction attribute may be specified on a business method M defined by class S to
override for method M the transaction attribute value explicitly or implicitly specified
on the class S.
• If a method M of class S overrides a business method defined by a superclass of S, the
transaction attribute of M is determined by the above rules as applied to class S.
Example:
@TransactionAttribute(SUPPORTS)
public class SomeClass {
public void aMethod () {…}
public void bMethod () {…}
…
}
@Stateless
public class ABean extends SomeClass implements A {
public void aMethod () {…}
@TransactionAttribute(REQUIRES_NEW)
public void cMethod () {…}
…
}
Assuming aMethod, bMethod, cMethod are methods of interface A, their transaction attributes are REQUIRED, SUPPORTS, and REQUIRES_NEW respectively.