2 Replies Latest reply on Sep 29, 2004 7:00 AM by akhammon

    Disappearing data...


      I have an entity bean that is representing a Oracle view in a database.
      I run the findAll() method for the bean and start processing the results, during the many hours it takes to complete this processing someone removes a row of data from the view. when I get to that row of data I blow up. see below

      2004-09-24 11:07:17,425 ERROR [org.jboss.ejb.plugins.LogInterceptor] Transaction
      RolledbackLocalException in method: public abstract java.lang.String com.paychex
      .oeg.employee.services.ejb.interfaces.EmployeeLocal.getSsn(), causedBy:
      javax.ejb.NoSuchObjectLocalException: Entity not found: primaryKey=168127

      the getSsn() method is an abstract method on the entity bean.

      My question is how can I keep processing the rest of the results of the findAll() when/if I run across a missing entity.

      Any help would be appriecated.
      Thank you all in advance.

        • 1. Re: Disappearing data...
          Johan Borchers Newbie

          You can put the processing of a single entity bean in a single method with a transaction attribute with e.g. RequiresNew. Call the method from another method with a loop. If the single method fails the transaction of the single method is rolled back.
          If your loop and single method are in the same bean your new transaction does not work when you do a direct call. Call the single method on the EJBObject like:

          MyLocalEJB localEjb = (MyLocalEJB) sessionContext.getEJBLocalObject();
          for (Iterator i = things.iterator(); i.hasNext();) {
          try {
          } catch (Exception e) {
          // correct something


          • 2. Re: Disappearing data...

            Right On,
            Thanks so much...

            Your suggestion worked like a charm. Although, I had to make another correction to handle the exception, which I will explain below, your suggestion ensures that if anything goes wrong I don't lose all the work I already did, Thanks again.

            To implement jobor's suggestion, I did exactly what he said to do, this meant I had to change the private method called in the loop to public and expose it on the local interface of my session bean with a RequiresNew transaction attribute, this worked to ensure that each iterationof the loop is a unit of complete work, instead of the entire process of iterating throught the loop being the unit of work.

            The other thing was, I also had to handle the NoSuchObjectLocalException which was the root of the problem in the first place, so I created an wrapper method on the entity that called the abstract accessor method. It handles the NoSuchobjectLocalException by returning null to the caller method.

            Believe it or not, these changes dramatically sped up the iteration of the loop. I was nicely supprised as I was under the impression that all of these new transactions would have the opposite effect.

            Thanks Again, JBoss Rules.