about EPractice Lab mock 2 question 9, stateless/stateful bean
posted 1 year ago
EPractice Lab, mock 2 exam question 9 ,
ATMEJB has method withdrawal() with Required transaction attribute and it is calling AccountEJB method getAmount(). At the same time, ChequeProcessorSessionEJB is calling getAmount() method of AccountEJB without any transaction context.
The algorithm for getAmount() is to deduct the amount from account balance, calculate interest, update history and return the requested amount to the caller.
What best describes the AccountEJB component?
a: AccountEJB should be stateless session EJB with Requires New transaction attribute for getAmount();
b: AccountEJB should be implemented as stateful session bean with Requires transaction attribute for getAmount();
c: AccountEJB should be implemented as message driven bean with support attribute for getAmount();
d: AccountEJB should be implemented as stateless session EJB with RequiresNew transaction attribute for getAmount();
First , I think choice a and d are the same.
Second, I think AccountEJB can be a stateful bean and getAmount() can have Require attribute .
1. getAmount() will executed either in the withdrawal()'s transaction or starts its own transaction.
2. It is fine to have two different AccountEJB instances for ATMEJB and ChequeProcessorSessionEJB respectively. The two instances of bean can access the database of a bank account at the same time to handle the amount deduction. The database can handle concurrent access.
Of course, AccountEJB can also be stateless, as I believe.