Transcation rollback from a bean

Discussions

EJB programming & troubleshooting: Transcation rollback from a bean

  1. Transcation rollback from a bean (4 messages)

    Hi

    We are having a situation where we a calling a stateless session bean (B1) method, say method A from another stateless session bean(B2) method, say B.

    A database insert operation in method A is resulting in a exception. In method B we are catching the exception and calling m_objSessionContext.setRollbackOnly() on the SessionContext object.But the record inserted in the database is not rolledback. Please help me understand the problem and guide me with the solution.

    Note: The transaction attributes for both the beans B1 and B2 is "Required" with a trasaction isolation level of "READ-COMMITED"

    Thanks in advance

    Awaiting a reply
    Deepa



  2. As you are using a stateless session bean, the transactional context of bean 1 method1 won't be
    accessible to bean2 method2.

    ejb spec says:

    A stateless session bean instance must commit a transaction before a business method returns.
  3. In the bean B1, the method does a explicit setRollBackOnly in case of exception. Will this not rollback the transaction in bean B2?

    Is there any other alternate to this problem.
  4. Hi,

    There is no conversional state maintained between methods when u are using Stateless Session Beans.
    Stateless SB's are only used for a instance of method invocation, use a single method to do the task of insertion. Then even u can implement transaction in it.

    Thanx & Reagrds
    Jawad
    jawad at vsnl dot com
  5. Actually you can rollback from stateless session beans you just need to make sure that you have disabled AUTO COMMIT on your database or ensure you have set up a TX DataSource. I assume since you are using context.setRollbackOnly that you have correctly specified Container under <transaction-type> in your ejb-jar.xml file.