Transaction handling in Stateless Session Bean

Discussions

EJB design: Transaction handling in Stateless Session Bean

  1. Transaction handling in Stateless Session Bean (9 messages)

    We are using WebLogic 5.1 (EJB 1.1). i have a stateless session bean which includes 2 calls to a BMP Entity bean. If one of the calls should fail then the transaction should rollback. But it does not happen in my case.
    The transaction attribute for the SB is RequiresNew and that for the EB is Required. If an exception is thrown in the SB then I catch it and rethrow an EJBException.
    The stack trace mentions that the transaction is rolled back but it does not reflect on the database.
    Could it be a problem with the DB(Sybase) driver?

  2. I've read that Java Transaction API (JTA)
    will take care for this sort of problem
    automatically, so do try it using JTA api.

  3. I've tried using bean managed transactions by using User Transaction interface but that too gives the same result...
    stack trace shows that the transaction has rolled back but database does not reflect that.
  4. Poorav,
    how are you getting the DB connection?
    1) DriverManager.getConnection
    2) DataSource.getConnection?
  5. I'm using DataSource.getConnection()
    Basiclly my EBs are calling a helper class which gets the connection using DataSourse.getconnection() and then executes the query.
  6. Lemme explain the scenario again -
    SessionBean method(){
    EB1.setOne()
    EB2.setTwo()
    }
    The 2 setters in the SB method should be included in the transaction. In the background setOne() and setTwo() use their individual connections and execute the update.
    Could it be that since 2 different connections are involved, the transaction manager commits automatically after each set method is called ?
    If so, what is the way around this problem?
  7. Transaction wise, have the session bean method() transaction declared as Required. For the entity bean methods use Required or Mandatory.

    Make sure that the connection is being obtained from a TXDataSource.

    Make sure that fixpack 6 or 8 is in use.
  8. Thanks Stephen
    I was using DataSource(non-transactional) instead TXDataSource(transactional) in weblogic.properties file.
  9. Sounds like the driver is auto committing, thus rendering the transaction meaningless. The transaction commit or rollback doesn't have any effect if the data has already been written to the DB.
  10. Weblogic won't support transaction unless u use service packs provided by them. So check it out in weblogic sites.