Which of the following EJB Transaction Attributes ensures that all transactions are always demarcated by the container (automatic demarcation)? TX_SUPPORTS TX_MANDATORY TX_REQUIRED TX_REQUIRES_NEW My ans is the first three choices. Plz confirm! thanx faiza
Required - Always runs in a transaction. If a transaction is currently in progress the ejb will join, if there is no transaction in progress than the container will create a transaction for the ejb to join.
RequiresNew - Container will always create a new transaction for this ejb or method any current transaction will be suspended until the new transaction completes.
Supports - Will join a transaction if no is in progress but will also work outside of a transaction if one is not in progress.
NotSupported - Will not join a transaction that may be in progress. Instead the transaction will be suspended until the bean completes, at which time it will resume.
Mandatory - A transaction MUST be in progress in order to call this bean. An exception will be thrown if called outside the context of a transaction.
Never - Doesn't want anything to do with transactions. Will throw an exception if a transaction is in progress when this bean is called.
Therefore, only RequiresNew guarantees that the transaction has been demarcated by the Container. The rest of the ones that you list can be involved in the transaction but that transaction may or may not have been created by the Container. The keyword in this question is ensures, only RequiresNew ensures the all transactions are demarcated by the container. [ September 17, 2002: Message edited by: Chris Mathews ]
Thanx...i had missed the Container part in the question. Heres another Tx related q. Ejb 1 has Tx attribute RequiresNew, ejb 2 has Tx attrib Required, ejb3 has Supports respectively. What happens to Tx of ejb 1 if Tx of ejb3 is rolled back. My ans: if T1 is ejb 1's Tx, and RequiresNew means that container starts T2, ejb2 requires tx so T2 continues, but ejb 3 rolls T2 back. So T1 will still exist and be committed. I think??? Plz comment! If anyone has to contribute any Tx q's ... u'r most welcome....i need to exercise my mind so plz give me some good tx q's. thanx faiza
Client calls EJB1, which calls EJB2, which calls EJB3. Is this your scenario? Here is the breakdown: Client calls EJB1. EJB1 is marked RequiresNew, therefore the Container creates a new Transaction X and suspends the current transaction if one is in progress. EJB1 joins the container demarcated transaction X. EJB1 calls EJB2. EJB2 is marked Required, since a transaction is in progress there is no problem. EJB2 joins transaction X. EJB2 calls EJB3. EJB3 is marked Supports, since a transaction is in progress EJB3 will join. EJB3 joins transaction X. EJB3 marks transaction X to rollback. EJB3 returns. EJB2 returns. EJB1 returns. Container sees that the transaction is marked to rollback and therefore rolls back transaction X. If a transaction was in progress before the call to EJB1 then the transaction will now resume. Therefore EJB3's rollback will cause the transaction that started with EJB1 to rollback but not affect any transaction started before EJB1.
Hi Chris, Is it possible to have different transaction attributes for different methods in the same bean as well as for the whole bean?. I heard you can have attributes for both (bean and methods)and in that case method level attributes will be taking precedence?. what about different attributes for different methods in the same bean. Please explain