I know that 'Required' and 'NotSupported' are the only transaction attributes allowed for the onMessage() method of an MDB. But is it possible to have other methods in the bean class (maybe for use within the bean only) for which I can assign other transaction attributes like 'Mandatory' ? I think this is allowed in entity and session beans, but what about MDBs ? Thanks Vipin
Even if EJB container will allow you to construct such bean and deploy it, there is not much use of such MDB, because it will constatnly throw "transaction required exception" (for 'Mandatory' attribute) ..... but, hm...
who will care about exception throwed from MDB?.... hopefully container will take care of it.... but, anyway, it will be useless bean....
hi Mikalai Thanks for your response, but I think you didn't understand my question. My question is this. Suppose I have a method named void testMe() in my MDB, which is called by onMessage() method. Can I set a transaction attribute of 'Mandatory' for this method, so that onMessage() method can call it only after starting a transaction ? Also I would like to know if we do specify transaction attributes for internal methods in the case of session and entity beans ? Thanks Vipin
I got it now... Yes, it looks reasonably... But it's like have "Supports" attribute for Entity EJB. We know that all Entity business methods have to be executed in transaction context, and we can't safely rely on context of bean caller. This not the right way. Bean Provider can't be sure that some one will not call such bean without valid Txn context. That's why *only* possible attributes for entity are : Mandatory, Required, RequiresNew In MDB situation is a little bit different, but container just would like to be *safe* and want to know how to handle any method call, does not relying Txn context of method caller (which will be separate method of the same bean), it just wants to be prepared to the worst situation : *NO* Txn context. If you look at this summary table you'll see that RequiresNew and Required behave exactly in the same way when client comes *without* transaction. The same for Supports and NotSupported. And, hey, don't forget that MDB can't use 'Never' or 'Mandatory', because they throw nice transaction exceptions, and MDB does not like any exception...... P.s. these are only my thoughts, I may be wrong, I definitely wrong, because got only 94% on SCBCD.... P.p.s. P.p.p.s. and this is out of scope of the test, btw.........
Originally posted by Vipin Mohan: Suppose I have a method named void testMe() in my MDB, which is called by onMessage() method. Can I set a transaction attribute of 'Mandatory' for this method, so that onMessage() method can call it only after starting a transaction ?
My guess is that if you try to use other transaction attributes for MDB,(go against the Bean Law ) either you may get a deployment error or run-time error. Doesn't "Required transaction attribute" always produce a new transaction context everytime onMessage() method is called?...Do you still need the Mandatory attribute?
Originally posted by Vipin Mohan: Also I would like to know if we do specify transaction attributes for internal methods in the case of session and entity beans ?
EJB2.0, sec 22.3, Spec P:460 Transaction attributes. The Application Assembler may define the value of the transaction attributes for the methods of the home and component interfaces of the enterprise beans that require container-managed transaction demarcation. All Entity beans and the Session and Message- driven beans declared by the Bean Provider as transaction-type Container require container-managed transaction demarcation. The Application Assembler uses the container-transaction elements to declare the transaction attributes. The bean law does not speak about the internal methods of the bean class... So I guess we are free to assume that all the private/public methods defined in the bean class, but not defined in the home/remote interface use the transaction context of the calling method.
Geez ! I almost forgot that we can't define transaction attributes for as you said internal methods of bean.. For MDB we can manage only onMessage method, and nothing else !!! So, can have in MDB : onMessage(...) auxMethod1(...) auxMethod2(...) but we CANNOT define transaction attributes for : auxMethod1(...) auxMethod2(...) and the the only 2 possible for onMessage(...) .......[you know yourself ]