ECommerce EJB transactions with multiple requests and response

Discussions

EJB design: ECommerce EJB transactions with multiple requests and response

  1. Can you explain how EJB container needs to be setup for an
    E-Commerce Application :

         -> -> ->
    User ->JSP -> EJB -> Database
         -> -> ->

    How do you maintain transactions across business processes that involve multiple requests and responses from the client. Figure illustrates multiple requests/response
    from user to JSP and how do you maintain all these
    requests which would invoke multiple EJB methods, in one
    transaction?

    Thanks in advance for your reply.
  2. There are generally two options using J2EE native facilities:
    1. Use client-side transactions.
    2. Use a statefull session bean with bean managed transactions.

    Option (1) may not be a very good idea, because it requires some transaction management logic in the web server. If you use a seperate web server (seperate from the App server), it may be difficult to set up the App server's transaction system on the web server. Potentially you can rely on CORBA interoperabillity to achieve this, but I wouldn't count on it.

    In order to implement option (2), make a BMT statefull session bean that starts a transactions on the first method invocation and ends it at some later invocation (after all the client requests are done). The container will retain the transaction context between the method invocations for you. Note that it is very important that you use a statefull bean - otherwise transaction context will not be retained.

    Gal
  3. Thanks for your reply, Gal !!

    There is a stateful session bean.
     and there are suppose two methoods -
    setOrder()
    setCreditCardInfo()

    We want both these methods in one transaction.

    So we do a begin transaction in setOrder(),
    and a commit in setCreditInfo().Is that it?
    Or do we have to set some flags too ?

    Just making sure, I got it.