Discussions

General J2EE: EJB Transaction Handling

  1. EJB Transaction Handling (4 messages)

    Hi,

    I have a doubt regarding EJB transaction handling.
     
    Suppose there is a session bean (stateless)that makes use of value objects and Data Access Objects. For this Session Bean, let us say we are using Container Managed transaction and the attribute of the method is set as "Requires". The DAOs uses a DataSource to get the connection. Will all the DAOs that are subsequently called by my bean method takes part in the transaction. In other words, does the transaction attribute setting "Requires" propogates down to all the objects and methods that are invoked by the bean method.

    Will the EJB Container automatically rolls back if any of the methods throw an EJBException or calls setRollBackonly().

    Thanks in advance..

    Jaise

    Threaded Messages (4)

  2. EJB Transaction Handling[ Go to top ]

    The answer to your quiestion lies in understanding how the transaction management works in J2EE. When a method with container managed transaction and transaction attribute of 'Requires' is called, a new transaction is started. All the transaction aware resources that are accessed by this thread then are added to the transaction(using enlist() and delist() methods in javax.transaction.Transaction class). When the method call ends the container calls commit/rollback on all the resources that are added based on the exception thrown / rollback attribute that is set.

    I am not sure of how the container identifies the transaction aware resources as there is no marker interface implemented to identify this.
  3. Yes the transaction will be rolled back. All database operations by any objects using the DataSource eg the DAO etc down the chain after the session bean will be rolled back.
  4. EJB Transaction Handling[ Go to top ]

    Hi,
       Yes all the database activities done by the DAO will be rolled back, once the Transaction is rolled back. But if you are using multiple datasources then make sure they are of type XA enabled. Because this will be enlisted under Two-Phase commit, which requires the resources be of type XA.
       If you are using WebLogic you may find this problem, but in AppServers like WebSphere you require it.
  5. EJB Transaction Handling[ Go to top ]

      If you are using WebLogic you may find this problem, but in AppServers like WebSphere you require it.
    Subash,
    Your last statement sounds misleading. Do you mean to say that Websphere DOES NOT require to have a Transactional Data Source (TxDataSource)???

    I would like to know whether the distiction between DataSource and TxDataSource exist in WebLogic only or with other AppServers as well.

    Thanks in Advance

    Jaise