Transaction confusion


EJB programming & troubleshooting: Transaction confusion

  1. Transaction confusion (6 messages)


    I have two session EJBs in a workflow. The first one has a method which has RequiresNew transaction state that calls an entity bean and makes some creates/updates in our DB.

    In the second session EJB a finder used to get data from the same entity. The data inthe entity isn't the updated info.

    Does the outer transaction have a different (cached?) view? Does my finder need to run in it's own (RequiresNew) transaction to see the latest info? I thought that the entity would commit as the method completes?

    Hope you can help


    Threaded Messages (6)

  2. Transaction confusion[ Go to top ]

    Both the session Beans will run under same transaction provided u have the transaction state as required/supports for the second session bean.
    So what ever DB operation you do in the first Bean will be visible to the second one.
    And everything will be commited/rolledback depending upon the success/failure in the second bean.

  3. Transaction confusion[ Go to top ]


    First up all , are the calls from session beans occuring sequentially or in parallel ?

    I guess looking at the description provided by you they are done one after another.

    method A {
       SessionBean1.insert/updateCall(); // uses RequiresNew


    Now findCall() is unable to get the updated info from insert/updateCall(). Is this correct ?
    Now what is the transaction sematics of findCall() method ?

    Ideally when sessionBean2's findCall method begins, appServer should load the latest data from DB into entity bean using ejbLoad(). And if this is happening correctly you should not face this problem.
    But with some appservers under stress, it can happen that the findCall references the older instances in memory.

    Now for you, is this the problem occuring always or only sometimes under load?
    If its happening under load then it seems like appServer issue.
    In that case, just print some timing information in ejbStore and ejbLoad and see if they are happening correctly.

    Hope this helps..

    Sangram ..
  4. Transaction confusion[ Go to top ]

    Hi Sangram

    The session beans are used one after the other. The first one will have completed before the second one is use. Both are called in the same transaction, they are called by another session bean which handles the workflow.

    The insert/update method is separately specified as RequiresNew in my descriptor because I always want the DB updates to occur. But the find method in the second session bean is not seeing the DB changes. This consistently happens.

    I will put some debug in the ejbLoad() method and let you know.

    Thanks again
  5. Transaction confusion[ Go to top ]

    The problem was that the method with transaction attribute set as RequiresNew was being called within a Session Bean. If I call it as a client of a Session Bean it works.

    It's the difference between calling


    in this session bean and

        UpdaterHome h = (UpdaterHome)getInitialContext.lookup("updater");
        UpdaterRemote r = h.create();

    i.e making this session bean a client of another session bean of this type.

    Anyway, thanks for the input and I hope you find this useful.

  6. Lee,

    I am facing a similar problem. Could you please explain a bit more what exactly you did to solve it?

    Here is my problem:
    1. Client invokes "save" method on a Session Bean (Facade).
    2. After save is over I call findByPrimaryKey to get remote again and invoke "getData" to get the latest data (from the session facade itself).
    3. What I get back is the state before the save (even though save was successful).

    I did put in debug statements and here is what I found:

    1. After save is called, findByPrimaryKey is executed successfully and ejbLoad is also called. I see that the new data is loaded properly.
    2. The getData () returns the old state (not the updated one).

    All my methods have "Required" attribute.

    Couple of other observations:
    1. When deployed in WEBLOGIC 8.1, this works fine. On WEBSPHERE 5.0.2, the above problem is noticed.

    2. If I move the getData () call out of session bean to the client it works fine. This is because the read call (getData) is in a different transaction now.

    In the first case, transaction is started when save is called. Same transaction is used for the read call and since it is not yet commited, OLD data is returned. (This is my understanding of the problem.

    BUT then, how come it works on WEBLOGIC and fails on WEBSPHERE?

    Any comments/ suggestions?
    Thanks in advance for your comments:
  7. Transaction Confuse[ Go to top ]

    hi all,
    I've got the same problem on Websphere. I've tested on JBOSS and WEBLOGIC.It runs well. In method F of a stateful session beanA with required transaction:
     - invoke a method of a stateless session bean B (required)
     - do a query DB (get the old state)
    It seems that the Websphere server consider the connection to another bean as managed resource, so the transaction will be commited after methodF.
    Further more, on Websphere, there is one parameter that indicate whether or not the server will updated to DB intermediately. But i dont know how to configurate the Websphere server.
    Any one help me?