4 Replies Latest reply on Oct 4, 2002 9:28 AM by Schneider

    run method in a transaction?

    Schneider Newbie

      Hi

      I have some troubles with the performance of my finder query.

      When call the method findAllAccounts (listed below) jboss exectute following
      SQL-queries:

      SELECT AccountId, AccountText FROM ACCOUNT WHERE (AccountId=0) OR
      AccountId=1) OR (AccountId=2) OR (AccountId=3)
      SELECT AccountId, AccountText FROM ACCOUNT WHERE (AccountId=0) OR
      AccountId=1)OR (AccountId=2)
      SELECT AccountId, AccountText FROM ACCOUNT WHERE (AccountId=0) OR
      AccountId=1)
      SELECT AccountId, AccountText FROM ACCOUNT WHERE (AccountId=0)

      as you can see an absolut performance disaster.
      I read in the JBossCMP document that this is normal if the method don't run
      in a transaction. After that i tried to change the ejb.transaction type for
      the method findAllAccounts to RequiresNew, but without any effect.
      I also tried to add the same to the ejb.finder, nothing happend.

      Now I absolutly don't know what i should do to solve this problem.

      I am using JBoss 3.0.3; XDoclet CVS-Version two weeks ago.

      thanks in advance,
      rudi

      /**
      * @ejb.transaction type="RequiresNew"
      * @ejb.interface-method view-type="both"
      **/
      public ArrayList findAllAccounts()
      {
      AccountLocalHome accountHome;
      ArrayList result;

      try
      {
      accountHome = AccountUtil.getLocalHome();
      result =
      AccountUtil.convertFromEntityBeanListToAccountValueListLocal(accountHome.findAll());
      ......

      signature of findAll-Finder:
      @ejb.finder signature="java.util.Collection findAll()"

        • 1. Re:  run method in a transaction?
          Alexey Loubyansky Master

          Are you calling finder and then iterate through the results?
          RequiresNew doesn't help here. Because the rows chached will be lost as soon as the transaction completes, i.e. finder successfully returns.
          The part that includes finder and iteration should be one transaction to make use of preloading data.

          • 2. Re:  run method in a transaction?
            Schneider Newbie

            I iterate through the result in the function 'convertFromEntityBeanListToAccountValueListLocal' (see above), but I think this is in the same transaction like 'findAll' (or not??).
            The client iterates through the converted List (ValueObjects), do this have any effect to the server??

            here is the code of the function 'convertFromEn....' perhaps there is an error I don't see:

            /**
            * Convert Collection of Entity beans to an ArrayList of Value Objects
            * used for local beanlist
            *
            * @todo optimize (use local interfaces)
            * @todo throw better exception
            */
            public static java.util.ArrayList convertFromEntityBeanListToAccountValueListLocal(java.util.Collection entityBeanList)
            throws Exception
            {
            java.util.ArrayList result = new java.util.ArrayList (entityBeanList.size ());
            java.util.Iterator entityIt;
            com.vescon.aum.server.iface.masterdata.AccountLocal entity;

            entityIt = entityBeanList.iterator();

            while (entityIt.hasNext())
            {
            entity = (com.vescon.aum.server.iface.masterdata.AccountLocal) entityIt.next();
            result.add (entity.getAccountValue ());
            }
            return result;
            }

            do this function also need a transaction tag??

            best regards,
            rudi

            • 3. Re:  run method in a transaction?
              Alexey Loubyansky Master

              >I iterate through the result in the function
              > 'convertFromEntityBeanListToAccountValueListLocal'
              > (see above), but I think this is in the same
              > transaction like 'findAll' (or not??).
              The same, unless findAll marked as RequiresNew.

              >The client iterates through the converted List
              >(ValueObjects), do this have any effect to the server??
              When getAccountValue() is called container checks whether the needed fields are already loaded and if not, then it loads them.

              Sorry, don't have ideas for now.

              • 4. Re:  run method in a transaction?
                Schneider Newbie

                I tried some more variants of tags.
                After setting the transaction-tags at the right positions AND defining a @jboss.read-ahead tag for the AccountBean it works!!
                --> read-ahead works, unoptimized do not!?

                I now use read-ahead (like I would do from the begining).

                thanks for all your answers,
                rudi