A question on Stateless session bean - Transaction Reg.


EJB design: A question on Stateless session bean - Transaction Reg.

  1. Hi

    This question might look simple but I need the answer to take a major decision in our project.

    Is it possible to achieve transaction between two stateless session beans?

    Say, Method-A in EJB1 with transaction attribute as "Required" and Method-B in EJB2 with transaction attribute as "Required". If method-A calls method-B, will the transaction be maintained? If any exception happens in method-A/B should rollback the database operations happened in both method-A and method-B.

    There can be two scenarios: i) Both EJB-1 and EJB-2 can be deployed in the same container ii) or different container (no clustering)

    Thanks for your response.

  2. Karthikeyan,

    Transactions between EJB1 and EJB2 will be maintained whether they are in the same container or in a different container(but same App Server)

  3. if its in the same container it will maintain the same transaction.
  4. Hi Satish & Selvaraj

    Thank you very much for your response.

    From your responses, I get the following doubts.

    Is that the transaction will be maintained only if both the stateless session beans are present in the same container?

    Will the transaction be maintained if the stateless session beans are in different containers of same application server type?

    What will happen if the application servers are different types say one is Oracle9iAS and another is weblogic?

    Please clarify me.

  5. distributed TX[ Go to top ]

    There will be 1 single transaction for both ejb's. Ejb A will start the tx, pass it to ejb B, and after B returns, still the same tx is active.

    If any ejb want's to rollback, the entire transaction will rollback, no matter who invoked setRollbackOnly.

    NOTE: to make this realy work, your DataSources must be XADataSource. This is a matter of configuring the resources of both containers. Only XADataSources can make distributed transactions work.