Hi Kathy,
Originally posted by Kathy Sierra:
Q1: Which three are true about transactions in EJB?
(Choose three.)
A) EJB 2.0 supports nested transactions.
B) EJB 2.0 allows you to specify isolation levels.
C) Message-driven beans must not use bean-managed transaction demarcation.
D) Entity beans must not use bean-managed transaction demarcation.
E) Stateful session bean state will not be rolled back if the transaction rolls back.
F) Stateful session beans that start a transaction must complete the transaction before ending a business method.
G) A message-driven bean must commit or rollback a transaction before onMessage returns.
IMO The Answer is C, D and G.
A - EJB 2.0 supports no nested transactions (see ejb 2.0 spec 17.1.2)
B - EJB 2.0 specify no isolaton leves (17.3.2 in the spec)
C - MDBs can use BMT, but must commit or rollback the transaction before returning from the onMessage() method (17.3.3).
D - Only MDB and Session Beans can use BMT (17.3.3)
E - It would be very expensive to implement such behavior in the container - The session should be passivated and stored on the start of the transaction, and reactivated on rollback - that would be a major performance killer ... also the SessionSynchronization interface would not make much sense.
F - SFSB can start a Transaction in one and end it in another business method, SLSB must end the transaction in the same business method.
G - It would not make sense to leave the transaction unfinished, MDB can be seen as a special case of a SLSB where the method invocator is a queue or a topic. See also (17.3.3). BTW This possibility is a bit vague, in the case of the CMT the MDB cannot commit or rollback the transaction (it can only mark it as rollback only or throw the EJB Exception)
Q2: Which two are true about bean-managed transaction demarcation?
A) A transaction used by a BMT bean MUST have been started by the bean.
B) The caller's transaction will be propogated into a BMT bean.
C) Transactions in a BMT bean do not propogate when the BMT bean calls a method on another bean.
D) A bean cannot use both CMT and BMT together.
E) BMT beans must not specify transaction attributes.
A, D, E
A - Since the bean manages the transactions, it must also start them.
B - That would be a conflict with the 17.1.2 - nested transactions are not supported by EJB 2.0
C - BMT and CMT are threated equally when a method on another bean is called (this option is also vague, the caller's transaction will will be suspended if the business method on another specifies RequiresNew or NotSupported transaction attribute)
D - It is not possible to define CMT or BMT on method basis - only for the whole bean
E - transaction attributes are specified only for CMT, see 17.3.6 and 17.4.1
BTW Kathy, 10x for investing your time and energy in our cert preparation, you are doing a great job!
Dragan