2 Replies Latest reply on Dec 10, 2003 6:01 AM by mmqwertz

    Transaction commited by FinderException?

    mmqwertz Newbie

      Hi I got a strange behaviour with a transaction. When I call the method findByPrimaryKey, the transaction gets commited. I did some debugging and had a look at my db-Server, so I can definetly say that the commit takes place when calling "findByPrimaryKey" and getting a FinderException. Any "setRollBackOnly()" in the catch block is too late.
      Here are some code and DeploymentDescriptor details:

      SessionBean:
      transferMoney(amount, toAccountNumber, fromAccountNumber) {
      decrease(amount, fromAccountNumber);
      increase(amount,toAccountNumber);
      }

      decrease(amount, accountNumber) {
      acc = homeAccount.findByPrimaryKey(accountNumber);
      acc.decrease(amount);
      }

      increase(amount, accountNumber) {
      //no commit so far...
      try {
      acc = homeAccount.findByPrimaryKey(accountNumber);
      } catch (FinderException e) {
      // here the commit has taken place!!!
      sessionContext.setRollbackOnly();
      }
      acc.increase(amount);
      }

      Deployment Descriptor part for transactions:
      ...
      <transaction-type>Container</transaction-type>
      ...
      <container-transaction>

      <ejb-name>TransferEJB</ejb-name>
      <method-name>transferMoney</method-name>

      <trans-attribute>RequiresNew</trans-attribute>
      </container-transaction>
      <container-transaction>

      <ejb-name>TransferEJB</ejb-name>
      <method-name>increaseBalance</method-name>


      <ejb-name>TransferEJB</ejb-name>
      <method-name>decreaseBalance</method-name>

      <trans-attribute>Required</trans-attribute>
      </container-transaction>
      ...

      Account is a container managed entity Bean.

      I also tried to set the findByPrimaryKey for Account to transactionAttribute "Required" but that didn't help.


      Any idea what I'm doing wrong?
      Thanks!
      Martin

        • 1. Additional Information to commit causes by finder Method
          mmqwertz Newbie

          I did some more research on the problem stated above. It doesn't really matter if the finderMethod throws an exception or produces a result, the transaction is always commited, as soon as I call a finderMethod!!!

          And setting transaction attributes for the CMP Entity Bean doesn't help either. I set "Required" for all methods but the problem keeps the same.

          Any suggestions?
          Might this be a bug in JBoss?

          • 2. Re: Transaction commited by FinderException?
            mmqwertz Newbie

            Ok, it was one of the beloved "read thefuckingmanual"-Problems.

            For all who might run into the same, here is the solution:

            By Default JBoss commits current transactions when a find, select or remove Method is called!
            This (in my opinion stupid) behaviour can be changed by setting <sync-on-commit-only> in the jboss.xml in tag <container-configuration> to "true".

            Some more details can be found in the jboss_3_2.dtd.