4 Replies Latest reply on Mar 7, 2012 3:55 AM by ashman

    Losing object references passed by EJB?

    ashman

      Hi,

      I am experiencing a problem, and was hoping someone could set me on the right path!


      I have two stateless EJBs CompanySessionBean and ObjectBrokerSessionBean. There is a method getCompanyStatusList in CompanySessionBean which in turn calls a method findAll on the ObjectBrokerSessionBean.

      This all seems to work fine. The return from the findAll is a collection of objects (populated with values from the database. Again, this works fine and I have checked that the collection contains 5 populated objects (as expected).

       

      The problem is that when the findAll method returns to the calling getCompanyStatusList method, the collection has 5 empty objects inside.
      So maybe the reference to the objects in the collection has been lost somewhere?

       

      I am using AS 7.1.0, and the EJB3.1.

       

      public abstract class BusinessObject
      {
         public void populate(ResultSet rs)
      {
        ...
        ...

        }
       
      }
      }

      public abstract class BusinessCodeObject extends BusinessObject
      {
        
          public void popultae(ResultSet rs)
          {
            
              super.populate(rs);
          }


      public class CompanyStatus extends BusinessCodeObject implements Serializable
      {
      public static final String CREATED  = "CREATED";
      public static final String ACTIVE   = "ACTIVE";
      public static final String INACTIVE = "INACTIVE";
      public static final String ONHOLD   = "ONHOLD";
      public static final String SELLOFF  = "SELLOFF";
      public static final String PROSPECTIVE  = "PRSPCTV";

      }

       

      @Stateless(name = "CompanySession")
      @Remote(IMaintainCompany.class)
      public class CompanySessionBean extends AbstractSessionBean implements IMaintainCompany {

            @Resource
            private SessionContext mySessionCtx;

           @EJB

           IObjectBroker brkr;

       

           public Collection getCompanyStatusList() {
                 Collection c = brkr.findAll(CompanyStatus.class);
                 return  c; // PROBLEM: c is a collection objects with nulls, rather than the populated values

                }

       

      }

       

       


      @Stateless(name = "ObjectBrokerSession")
      @Remote(IObjectBroker.class)
      public class ObjectBrokerSessionBean implements IObjectBroker {

      @Resource
      private SessionContext mySessionCtx;


      public Collection findAll(Class clazz) {
             Collection ret = new ArrayList();
             Connection c = null;
             ResultSet rs = null;
             CallableStatement cs = null;


              c = DatabaseConnectionFactory.getConnection(DATASOURCE);
              String sql = "call da_company_status.SEL_ALL (?)"

              cs = c.prepareCall(sql);

              cs.registerOutParameter(1, OracleTypes.CURSOR);

              cs.execute();

              rs = (ResultSet) cs.getObject(1);

        

           BusinessObject bo;

           while (rs.next()) {
               bo = (BusinessObject) clazz.newInstance();    
               bo.populate(rs);
               ret.add(bo);

            }

       

         return ret; // ret is a collection with objects containing values populated from the database

      }

        • 1. Re: Losing object references passed by EJB?
          jaikiran

          Are all the contents of CompanyStatus serializable? Can you give it a quick try to change the business interface from @Remote to @Local (assuming the client is in the same application)?

          • 2. Re: Losing object references passed by EJB?
            ashman

            Hi Jaikiran,

             

            Yes that was my initial thought as well, but the CompanyStatus object has nothing more than a few static final Strings and it implements Serializable already. Yesterday I changed everything to @Local, and yes, it does work perfectly. In this application, I dont need to have the interfaces as @Remote, but I still can't understand why it doesn't work. I read somewhere that there were some bugs reported with Remote RMI invocations in AS7, but I thought the issues were solved for 7.1.0 Final (which is what I am using).

             

            Thanks,

            Ash

            • 3. Re: Losing object references passed by EJB?
              jaikiran

              ashman wrote:

               

              Hi Jaikiran,

               

              Yes that was my initial thought as well, but the CompanyStatus object has nothing more than a few static final Strings

              I actually meant the entire hierarchy of that class including the base classes.

              • 4. Re: Losing object references passed by EJB?
                ashman

                Yeah, I tried that yesterday too, but due to the way the classes are structured (the base classes for CompanyStatus are used all over the place), I started to get compilation errors, and as I wasnt sure whether that would be the problem, I didnt want to go and start hunting those down. Is that your gut feeling? Do you think that would be the source issue here?