question about programming technique for bean-managed transactio

Discussions

EJB programming & troubleshooting: question about programming technique for bean-managed transactio

  1. Hi folks

    It is highly appreciated some EJB guru can provide me with some opinion on my below questions.

    1) To use bean-managed transaction, the UserTransaction interface can be acquired through javax.ejb.EJBContext or through JNDI lookup with env entry, java:comp/UserTransaction. Technically, is there any difference in these two approaches.

    2) According to p177 of ejb 1.1 spec, If there is a transaction associated with the stateful ejb instance (this would happen if the instance started the transaction in some previous business method), the Container automatically associates the method execution with this transaction. However, if within the business method, UserTransaction.begin() is invoked again, will the exception be thrown or the transaction will be automatically enlisted in the existing transaction associated with the bean instance.

    3) Let's say that l have a implemented a stateful session bean as a controller. When request come in the stateful session bean controller which use bean-managed transaction, the controller will then instantiate a few java classes to handle the incoming request. Within these java classes, transaction will be started by acquiring UserTransaction interface through JNDI lookup. Is the UserTransaction interface returned through JNDI lookup within these java classes equal to the SAME transaction associated with the stateful session bean controller.

    thx and regards
    dso
  2. 1) To use bean-managed transaction, the UserTransaction interface can be acquired through javax.ejb.EJBContext or through JNDI lookup with env entry, java:comp/UserTransaction. Technically, is there any difference in these two approaches.

    A) The JNDI lookup method is designed for clients to use, who do not have an EJBContext, such as a JSP or a standalone client. The EJBContext is easier and faster.


    2) According to p177 of ejb 1.1 spec, If there is a transaction associated with the stateful ejb instance (this would happen if the instance started the transaction in some previous business method), the Container automatically associates the method execution with this transaction. However, if within the business method, UserTransaction.begin() is invoked again, will the exception be thrown or the transaction will be automatically enlisted in the existing transaction associated with the bean instance.


    A) The container should throw an exception. As shown in section 17.6.1

    "When an instance attempts to start a transaction using the begin() method of the javax.transaction.
    UserTransaction interface while the instance has not committed the previous transaction,
    the Container must throw the javax.transaction.NotSupportedException in the
    begin() method."

    3) Let's say that l have a implemented a stateful session bean as a controller. When request come in the stateful session bean controller which use bean-managed transaction, the controller will then instantiate a few java classes to handle the incoming request. Within these java classes, transaction will be started by acquiring UserTransaction interface through JNDI lookup. Is the UserTransaction interface returned through JNDI lookup within these java classes equal to the SAME transaction associated with the stateful session bean controller.

    A) Yes this will be the same transaction context.

    Dave Wolf
    The Scupper Group
    dave at scuppergroup dot com