EJB.14.6 UserTransaction Interface


EJB.14.6 UserTransaction Interface

Note

The requirement for the container to publish the UserTransaction interface in the enterprise bean's JNDI API context was added to make the requirements on UserTransaction uniform with the other Java 2 Platform, Enterprise Edition application component types.


The container must make the UserTransaction interface available to the enterprise beans that are allowed to use this interface (only session beans with bean-managed transaction demarcation are allowed to use this interface) in JNDI API under the name java:comp/UserTransaction.

The container must not make the UserTransaction interface available to the enterprise beans that are not allowed to use this interface. The container should throw javax.naming.NameNotFoundException if an instance of an enterprise bean that is not allowed to use the UserTransaction interface attempts to look up the interface in JNDI API.

The following two code examples are functionally equivalent public MySessionBean implements SessionBean {

Example 1.
 ...     public someMethod()     {       Context initCtx = new InitialContext();        UserTransaction utx = (UserTransaction)initCtx.lookup(          "java:comp/UserTransaction");        utx.begin();        ...        utx.commit();     }     ...  } 
Example 2.
 public MySessionBean implements SessionBean {    SessionContext ctx;     ...     public someMethod()     {       UserTransaction utx = ctx.getUserTransaction();        utx.begin();        ...        utx.commit();     }     ...  } 


Java 2 Platform, Enterprise Edition. Platform and Component Specifications
Java 2 Platform, Enterprise Edition: Platform and Component Specifications
ISBN: 0201704560
EAN: 2147483647
Year: 2000
Pages: 399

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net