1 Reply Latest reply on Dec 30, 2013 3:14 PM by Sheeraz Junejo

    Accessing <transaction-type> configration of ejb-jar.xml in EJB class

    Sheeraz Junejo Newbie

      I have an EJB deployed with configurations in ejb-jar.xml and I would like to access <transaction-type> configurations i.e. Bean or Container as I have to pass this value to my framework for internal work.

       

      Note: I do not want repeat and define an additional env-entry for the same as its already there and I would like to use it

        • 1. Re: Accessing <transaction-type> configration of ejb-jar.xml in EJB class
          Sheeraz Junejo Newbie

          I found out that we do not have any way of directly accessing this information.

           

          However, you can get at the information indirectly by relying on the fact that EJBContext.getUserTransaction throws an exception for CMT:

          @Resource EJBContext ejbContext;

          private boolean isBeanManagedTransaction() {

               try {

                    ejbContext.getUserTransaction();

                    return true;

               } catch (IllegalStateException e) {

                     return false;

               }

          }

          Note, the getUserTransaction method cannot be called from all container callbacks (see the table of allowed operations in the EJB spec), but fortunately, getUserTransaction can be called from ejbCreate/PostConstruct, so this method works for me.