Starting new transaction from Synchronization listener


EJB programming & troubleshooting: Starting new transaction from Synchronization listener

  1. I have a system that uses 100% container managed stateless session beans. I have a need to listen when a particular transaction is completed, then call another bean to do some additional work. (This is OC4j 9.0.3 by the way). I created an object that implements javax.transaction.Synchronization. In the afterCompletion() method, I instantiate my new bean and make the call. The problem is the container does not start a new transaction for this second call -- it runs the method without a transaction. The transaction attribute on the method is "Required".

    Is this expected behavior, or is it a bug with Oracle's app server? If this is expected behavior, does anyone know of another way to safely listen for transaction commit events? Am I allowed to start a transaction manually from a Synchronization listener from the afterCompletion() call?
  2. Hai,

        Good question. Here one thing you need to know bcs your session be implements with SessionSynchronization once you call a method of remote interface the transaction will be committed or rollback after your aftercompletion method finished. Since ejb does not support nested transactions your requirement will not possible. You can call your second transaction once you finish your first transaction. I mean you can write one more method in session bean or where you are calling session bean and then you can call that method once your first transaction completes.

    Kiran N