To complete a transaction, which Transaction Attributes or Isolation Level should be used for a stateless session bean?

Gene De Lisa

[For example, I have a method transfer which transfers funds from one account to another account.]

Vague question. Is the Session bean doing the DB work? I'll assume no.

Let's say AtmEJB is a Session bean with the transfer method. Let's say AccountEJB is an Entity bean.

Step 1:

When the client invokes the transfer method you want that to be the transaction; i.e. "the transfer transaction". therefore you need to set the tx attribute of transfer to something that will make the container start a tx at the beginning of transfer and terminate it at the end of transfer. RequiresNew might be a good choice but you need to look at all your use cases not just this one.

Step 2:

The AccountEJB methods invoked from the transfer method need to have a tx attribute that allows them to be part of an ongoing tx. That means that deposit and withdraw cannot be RequiresNew! (that would suspend the transfer tx and run in its own tx). Look at the spec for these: there are 3 that meets the criteria for deposit and withdraw in the transfer use case. Which one to use? What are the other use cases in which deposit and withdraw will be called? Find one that works for each one.