A developer is working on a user registration application using EJB
A business method registerUser in stateless session bean RegistrationBean performs the user registration.
The registerUser method executes in a transaction context started by the client.
If some invalid user data causes the registration to fail,
the client invokes registerUser again with corrected data using the same transaction.
Which design can meet this requirement?
A. Have registerUser method call EJBContext.setRollbackOnly() method after registration fails
B. Have registerUser method throw javax.ejb.EJBTransactionRequiredException after registration fails
C. Have registerUser method throw EJBException without marking the transaction for rollback, after registration fails
D. Create an application exception with the rollback attribute set to false and have registerUser method throw it after registration fails
I got the Answer is D , but I think it may be wrong because Application Exception must have Rollback = True
to get automatic rollback if it is not rumetimeexception or any uncheck exception .
A option is wrong , reason is below list
The setRollbackOnly and getRollbackOnly methods can only be
invoked in an EJB using CMT with these transaction attributes: REQUIRED,
REQUIRES_NEW, or MANDATORY. Otherwise, the container will throw an
B option javax.ejb.EJBTransactionRequiredException seem not to exist
C option is only one could be right answer .
Will someone could answer this question ? thanks a lot