4 Replies Latest reply on Apr 18, 2002 12:46 AM by David Jencks

    Transaction Rollback and database synchronization problem

    Navdeep Newbie

      Hi,
      I am using JBoss-2.4.3 and Jetty-3.1.1-1 package on an NT 4.0 machine.
      The commit option in the standardjboss.xml file is set to "B" (option "C" was also tried).
      We Have a set of Session beans which Use Entity beans (All are BMP's) to access the database and manipulate the data. The Transaction attribute for all methods in the entity beans is set to "Required". And the method in the session bean invoking the methods in the entity beans have the attribute "required".
      The table on which the entity bean is based on in the database, has some update triggers, which change some of the data upon updation.
      The scenerio is something like this:
      Client calls SessionBeanA.MethodA (this method has the transaction attribute "Never"). MethodA calls MethodB in the same session bean (with transaction attribute set to "required"), MethodB does a findByPrimaryKey and gets a reference to the EntityBean and calls a method in the entity bean which updates the data in the database, at this point methodB finishes, but before it finishes if it encounters a problem then it calls SessionContext.setRollBackOnly(), which should rollback the changes made by the entity bean.
      But it does not to so, the changes get commited to the database.
      Any help would be greatly appreciated. Please let me know if any more information is required.

      P.S. I have also tried playing around with other combinations like "required", "notSupported" and none of them give the desired results. Also even with Option "C", I have fouund combinations where the data in the entity bean was not synchronized with the database. Is there a known bug.

        • 1. Re: Transaction Rollback and database synchronization proble
          Navdeep Newbie

          When I say that the Entity bean updates the data in the database, it actually updates the values into the database only when the ejbStore gets called. No other method in the entity bean updates the datase directly.
          I apologise about not being clear about that.

          • 2. Re: Transaction Rollback and database synchronization proble
            David Jencks Master

            Are you calling the second SessionA method through the remote interface for SessionA or doing a direct java object call on the current instance? The latter will result in every call to an entity bean being in its own transaction, the session will never start one.

            • 3. Re: Transaction Rollback and database synchronization proble
              Navdeep Newbie

              Thanks for the quick reply david. I am calling MethodB in session bean from within the methodA itself and not through the remote interface. I have also tried making MethodA as "Supports" and "required". And if you say calling MethodB from within MethodA will result in every method having its own transaction. How can I acheive what I want to do and that is have all methods called in entity bean from MethodB be part of the same transaction.
              But as soon as I exit MethodB the transaction should Commit. And then when MethodA calls MethodC, which in turn tries to look up the same record through the entity bean it should see the changed data.
              Thanks again for looking into the problem.

              • 4. Re: Transaction Rollback and database synchronization proble
                David Jencks Master

                The only way the container can keep track of what you are doing is if the method calls go through the remote interface. If you call methodB from methodA directly, as far as the container is concerned, you are still in methodA, with no transaction. So each call to an entity bean (Requires) will get a new tx. Call methodB through the remote interface.