MyBean calls ejbLoad()/ejbStore() under a bussines method call

Discussions

EJB programming & troubleshooting: MyBean calls ejbLoad()/ejbStore() under a bussines method call

  1. Hello.
    Why does my Entity EJB call ejbLoad()/ejbStore() lots of times (say 16 or around) each time I call one bean's bussines method?

    This is my scenario:

      public class MyBean extends EntityBean {
        BigDecimal pk;
        String aText;
        MyBeanA beanA;
        MyBeanB beanB;
        ...

        public void ejbLoad() {
          ...
          this.aText = aResultSet.getString(1);
          this.beanA = beanAHome.findByPrimaryKey(pk);
          this.beanB = beanBHome.findByPrimaryKey(pk);
          ...
        }

        public int getValFromBeanA() {
          return beanA.getTheVal();
        }
      }

    I use Sun's j2eesdk1.2.1 reference implementation as developing plattform.
    MyBean acts as MyBeanA and MyBeanB client. When I call getValFromBeanA method, this causes lots of ejbLoad()/ejbStore() calls. Is that a Sun's bug or is there an explanation?

    Also I get a RemoteException when executing beanA.getTheVal(). I tryed using both 'Required' and 'Supports' for Transactions.

    I am planning moving to iPlanet as my developing plattform. Is this worthy? I decided using the Sun's RI 'cause I found it enought and cheap ;-)

    I really thank any idea.
    Cheers:
    J. Carlos Muro
  2. Hi,

    The server is probably using Option C for Commit options.Here whenever a method is called a select SQL is fired and all the instance fields are populated.Once the transaction is completed,ejbStore() is called.If u do not want this try Option A.In this EJB has exclusive rights on the DB.U must ensure that no other application is updating the DB

    Bye

  3. Where is the transaction boundary?

    If all of your calls are made within a single transaction, then there will be only one store at the end of the transaction.

    If a transaction is started every time you run an entity bean method, then there will be a store after each method call.

    You have to understand what the transaction boundaries are in order to control how many stores you do.