ejbActivate() & ejbPassivate() methods are called 10,000..times


EJB programming & troubleshooting: ejbActivate() & ejbPassivate() methods are called 10,000..times

  1. We have a project with many Entity Beans, and all of them have relations with one another. The simple example I can give is Entity A has one to many relation with Entity B.
    i.e There could be one Entity A and for this there could be many Entities B these two entities are managed by CMR fields.
    Entity A has a PK, this would act as a FK in Entity B.

    In the EJB Post create method of Entity B I am trying to find a suitable entity A and trying to execute setEntityA(suitableEntityA), while this method is getting executed here is the things that happen
    the container tries to find all Entity B (if there are 10,000 records in B table then ejbActivate() of B is executed 10,000 times) then it sets the relation with Entity A, then at the end of the Transaction the container will call ejbPassivate() method on Entity B 10,000 times!!! oh god what is happening here...!!!?????
    can some one tell me if I am missing some settings?
    The same thing happends for all the other EJBs which have one to many CMR fields, i.e ejbActivate() and ejbPassivate() of each of these Entity Beans will be called for those many number of times for as many records found in the Datbase of the corresponding Entity.

    I have the follwing setting in my orion-ejb-jar.xml file

    <entity-deployment name="EntityA"

    similar xml construct for Entity B also!!!

    If some one knows more about this please let me know.

    Thank you
  2. Found one more thing for this CMP-CMR relationship and ejbActivate() and ejbPassivate() process of CMP Entity's.
    In this above example if say
    Entity A (Dept) ------ Entity B (Employee) (1:M) has one to many relationship
    Employee holds a FK value which is PK in Dept (dept_id).
    Suppose asssume that there are 10,000 employees working for a dept_id = 5.
    (i.e there are 10,000 records in Employee that references Dept table with dept_id =5)
    Now I want to add one more employee to this dept_id = 5, then I create an Employee entity and in the ejbPostCreate() method of Employee entity I lookup Dept Entity with Dept_PK=5, until this every thing is fine. Now I call setter method with in Employee Entity to set the dept such as setDept_dept_id(detpEntity5), at the execution of this method EJB container calls starts calling Employee Entity's the ejbActivate() method for 10,000 times this equals the number of references Employee table has to Dept table with Dept_ID=5, then at the end of the transaction the container calls ejbPassivate() method 10,000 times to passivate all those ejbs that it activated.
    Did some one experience the same thing with CMP EJBs? please let me know what I have to do to avoid such things?

    Thank you