wood burning stoves 2.0*
The moose likes EJB and other Java EE Technologies and the fly likes Transactions in Stateless beans ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Transactions in Stateless beans ?" Watch "Transactions in Stateless beans ?" New topic
Author

Transactions in Stateless beans ?

Jack Nicholson
Ranch Hand

Joined: Sep 07, 2002
Posts: 41
Hi,
I am having problem with one of the logic that how stateless beans can be used for transactions?
ATM's also uses the logic of stateless beans.
But the problem is when one is doing the transaction, how can we guarantee that the same person/ or other using his id, can do the transaction at the same time?

Thanx


Jack Nicholson
Dave Landers
Ranch Hand

Joined: Jul 24, 2002
Posts: 401
Transactions provide something called ACID. That means that the work you do within the transaction is Atomic, Consistent, Isolated, and Durable.
I think the one you are asking about is Isolation. Transactions are isolated from each other. That means that whatever I do in my transaction won't mess up anything you are doing. Even if we do the work at the same time or whatever.
Databases can choose to implement this isolation in many different ways, but they basically come down to some form of locking or versioning.
A database might put a lock on the table or row so that the second transaction is stalled until the first one finishes. This is called Serializable access to the data.
Or, a database might use Optimistic Locking - it keeps track of a version id for the data, and when the second transaction commits, if it sees "wrong version" it throws an exception.
There's a bit more to it than that, but the main thing to know is that this is a function of the transaction (or, more specifically of the transactional resource such as database).
I'm not sure I really understood your question - did I get anywhere close?
Jim Baiter
Ranch Hand

Joined: Jan 05, 2001
Posts: 532
If the call to the slsb (stateless session bean) failed the whole transaction can be rolled back. There are many situations where you could want this.
Chris Mathews
Ranch Hand

Joined: Jul 18, 2001
Posts: 2712
Actually it depends on how it failed as to whether it would be rolled back.
If the call failed with a System exception (RuntimeException and its subclasses) then the transaction would be rolled back per the EJB specification. EJBException falls in this category, as well as RemoteException.
If the call failed with an Application exception then the transaction would need to be explicitly marked by the EJB for rollback. CreateException, DuplicateKeyException, FinderException, ObjectNotFoundException, and RemoveException all fall in this category.
Jack Nicholson
Ranch Hand

Joined: Sep 07, 2002
Posts: 41
Yes Dave, I agree with your view that we can set ACID properties of the business methods. & also
about Database row level locking.
I got that well.
But
& one more thing to clear about is,
The properties which supports during CMP, will be applicable to StatLess. Bean or not? ie- if i do transaction, in stateless / CMP what will be the net effect to Server? & which will offer good performance?
& b'Cause CMP does not supports retrieval of heap of rows from d/b, Wheather it is applicable to Statless too?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Transactions in Stateless beans ?