Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

need clarification on transaction

 
james edwin
Ranch Hand
Posts: 393
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

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.

Regards,

James
 
Roger Chung-Wee
Ranch Hand
Posts: 1683
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
james edwin
Ranch Hand
Posts: 393
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Roger Thanks for reply.

But what's wrong with this..i want to run m1() in transaction and m2() method in no transaction context. Why this is not allowed ?

This could be very much possible to have one method in transaction and other method not.

Regards,

James
[ May 28, 2004: Message edited by: james edwin ]
 
Roger Chung-Wee
Ranch Hand
Posts: 1683
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Dale Seng
Ranch Hand
Posts: 275
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think I can muddy the waters significantly...

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.

After much labor, I found this discussion.

--Dale--
 
Roger Chung-Wee
Ranch Hand
Posts: 1683
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic