EJB Programming


EJB programming & troubleshooting: EJB Programming

  1. EJB Programming (1 messages)


    I use bean managed transaction in my projects. Can i initiate a transaction in one method and do a commit or rollback in another method?

    Can anybody clarify me on this.

    Thanks in advance

  2. EJB Programming[ Go to top ]

    Yes you can. But this feature is not limited to BMT. you can do the same with CMT too.

    propagating transaction across methods lets you keep the benefits of a single transaction- single transaction and single commit- while letting you break up large sections of code into multiple methods and beans.

    For CMTs, you need to ensure that the methods being invoked from within a transaction DO NOT USE "RequiresNew","Never", or "NotSupported". Anything else is fine. This way the current transaction will be propagated.

    For BMTs, use ejbContext.getUserTransaction() method in all the methods to obtain the current transaction and it will remain the same for every invocation of the method.

    NOTE: These instructions do work only for stateful session beans. NOT for stateless beans

    Reference: EJB CookBook by Benjamin G. Sullins, Mark B.Whipple

    Good luck!

    -vaheesan selvarajah