Discussions

EJB programming & troubleshooting: Access transaction attributes from EJBs

  1. Access transaction attributes from EJBs (2 messages)

    My session bean may take connection from one of 2 available pools. Its choice depends on transaction attribute that was defined on this bean (it is defined globally for all methods).
    My question is:
    How I can access transaction attribute value that was defined in ejb-jar.xml (not reading the file directly, but via some API)?
    Thank you.
  2. I don't think that there is a way to do that in stanard J2EE API,
     it might be avaliable ,however, through the AppServer you are using.

     a manual way which might work :
     through your bean try locating the URL of the ejb jar which is the source of
     your bean , using a code like that :
       
        sbean.getClass().getProtectionDomain().getCodeSource().getLocation()

     then init a classloader which include in its path the jar and use the
     getResource() method to locate the ejb-jar.xml
     
     ofer
  3. Hi,
    The transaction attributes are deceided at deployment time. Simmilar, you should deceide the connection pool (datasource) at deployment time. This can be done through an env-entry in your bean deployment descriptor, or some other config strategy (property files in calsspath, etc).
    Best regards,Mircea