Session Bean and Container Managed Transaction Demarcation


EJB design: Session Bean and Container Managed Transaction Demarcation

  1. Either I'm making a huge mistake or missing something...

    Let's assume we've got 2 EJBeans;
    - A Session Bean with one method doSomething() with a transaction attribute set to "Required" or RequiresNew" which makes use of container managed ransaction demarcation.
    - An Entity Bean which has 2 attributes with corresponding getX/setX methods.

    In doSomething() the following is done:
    1. Lookup EntityBean
    2. EntityBean.setX(value)
    3. EntityBean.setY(value)

    I'm under the assumption that the container will implicitly start a transaction when doSomething is called upon (before 1.). After that all calls that result in altering a database (so 2. and 3.) are enlisted in this transaction that will be closed by the container after 3. This means that 2 and 3 are not treated as seperate transactions towards the database. AFAIK this is what's meant in the EJB 1.1 spec par

    Is this the truth or am I indeed missing something? I was triggered by Beth Stearns' article "Designing Entity Beans for Inproved Performance" on where she states:

    Some of the drawbacks


    Notice, too, that each method invocation involves a separate transaction. By design, the EJB container handles transaction demarcation in this fashion. It's possible for the client to get around this if several attributes need to be updated within one transaction, but then the client must use client-side transaction demarcation. That is, the client developer must write transaction code, which makes more work for the client developer and negates some of the value of the EJB architecture.

    In my example it's possible to let the container do the work without having the "client developer must write transaction code".

    Am I correct?

    Michel Teunissen

    michelteunissen at escador dot com
  2. Dear Friend,
      Hai , You are absolutely right.There is no need of any
    client interaction ,so one can have the setting by calling Entity thru Session beans.Cmp will do all the transaction for you.
      Pl. if you have time then you can show me your complete
    source code .ur making error in interfaces.
  3. It's not my intention to list the right interfaces. I'm just trying to make sure I'm not misunderstanding the concept of container managed transaction demarcation when it comes to calling multiple set-methods on one CMEB from within on method on a SB. If I'm right, then Beth Stearns is wrong in her article on
  4. No. Beth Stearns is not wrong. She was referring to TX management in entity beans. Your session bean plays the role of a client to the entity bean, so you don't need to start a user transaction.