I was going through EJB SPEC 2.0 and read below paragraph on page number "82".
Quote ************* If a session bean instance is participating in a transaction, it is an error for a client to invoke a Method on the session object such that the transaction attribute in the deployment descriptor Would cause the container to execute the method in a different transaction context or in an Unspecified transaction context. In such a case, the container throws the java.rmi.RemoteException *************
Suppose we client C which call method mA() on instance A (SB instance) and method mA() is required.
So when can we get this exception or can someone put more light on above para with example.
Let's say m1() is running in a transaction and calls m2() whose transaction attribute is Never. This is illegal, so the container throws RemoteException to a remote client or EJBException to a local client.
If m2() has a transaction attribute of NotSupported, the container will suspend m1()'s transaction and then run m2() in an unspecified transaction context. When m2() completes, m1()'s transaction is resumed.
On the surface, at least, the spec and the book left me wondering about concurrent access, and more specifically, concurrency within transactions.
I concluded (possibly incorrectly, that's up to you) that a bean gets 'tainted' if a transactional method runs on it, and that transaction, for whatever reason, remains open, and some other bean comes along and tries to run a method while that original transaction is still open. That first method may have completed very nicely, but, for watever reason, the transaction was still open when that second method call came in.
Thanks for the reminder that nested transactions are not allowed. Here's how I understand it, with a little example.
Let's say that m1() has a transaction attribute of Required, m2() has a transaction attribute of RequiresNew.
Scenario 1 ========== A client starts a transaction, calls m1() and then m(2).
client --> m1() \--> m2()
In this case, the client's transaction is suspended and m2() runs in a new transaction.
Scenario 2 ========== A client starts a transaction, calls m1() which calls m(2).
client --> m1() --> m2()
In this case, m1() is still in an open transaction when the attempt is made to call m2(). This is a nested exception, it is disallowed and the Container will throw a RemoteException or an EJBException.