Discussions

EJB programming & troubleshooting: Sun ONE finder problems

  1. Sun ONE finder problems (5 messages)

    Hi all.

    I am getting a headache! This problem is so odd, I can hardly describe it. I have a method in my Facade (stateless session bean) which return a value object with the following signature:

    public CustomerSetupDate getCustomerSetupData(Long customerId)

    This is what the code looks like:

    CustomerSetupData csd = new CustomerSetupData();
    try {
        LocalState state = stateHome.findByPrimaryKey(new Long(1));

        System.out.println("finding customer with id: " + customerId);
        LocalCustomer customer = customerHome.findByPrimaryKey(customerId);
        csd.setCustomer(FacadeCopyHelpers.copyCusotmer(customer));
        
        Collection c = personHome.findContactPersons(state, customer);

        Iterator it = c.iterator();
        while (it.hasNext()) {
            System.out.println("adding contact person");
            csd.addContactPerson(FacadeCopyHelpers.copyPerson((LocalPerson)it.next()));
        }
    } catch (FinderException e) {
        throw new EJBException("Could not find customer setup data with id: " + customerId, e);
    }
    return csd;

    When this method is called it should find the customer with the supplied customerId and then find all the contactPersons that are associated to this customer which happens with the findContactPersons(state, customer) method.

    Now here is the problem. First time I call this method everything works fine. All the contactPersons are found and added. The second time (and third, fourth and so forth) the method is called with a different customerId the findByPrimaryKey return the associated customer, BUT the findContactPersons method returns all the contactPersons which are associated to the first customer. Why?

    My primary key class is java.lang.Long. In addition I can tell you that all my finder methods which takes another Local-interface as parameter behave the same way.

    Thanks if anyone can supply me with some hints.

    Yours sincerly

    Allan Lauridsen

    Threaded Messages (5)

  2. Re: Sun ONE finder problems[ Go to top ]

    I assume you're using CMP (i.e. not BMP), am I right?
    If so, would you please post your EJBQL of findContactPersons() method?
    If you're using BMP, would you please post your JDBC query?
    Also, think twice, is there any possibility you cache the Collection somewhere and just re-use it?
  3. Re: Sun ONE finder problems[ Go to top ]

    Hi Alan

    Thanks for your quick reply. I have thought twice over and over again... the findContactPersons() method returns the same.

    Correct, I am using CMP 2.0! My EJBQL looks like this:

    <query>
    <query-method>
      <method-name>findContactPersons</method-name>
      <method-params>
        <method-param>dk.proactive.sales3.ejb.statics.LocalState</method-param>
        <method-param>dk.proactive.sales3.ejb.dynamics.LocalCustomer</method-param>
      </method-params>
    </query-method>
    <ejb-ql>SELECT Object (p) FROM Person AS p WHERE p.state = ?1 AND p.customer = ?2</ejb-ql>
    </query>

    The relationship description between Person and Customer is here:

    <ejb-relation>
          <ejb-relation-name>Person-Customer</ejb-relation-name>
          <ejb-relationship-role>
            <ejb-relationship-role-name>Person</ejb-relationship-role-name>
            <multiplicity>Many</multiplicity>
            <relationship-role-source>
              <ejb-name>Person</ejb-name>
            </relationship-role-source>
            <cmr-field>
              <cmr-field-name>customer</cmr-field-name>
            </cmr-field>
          </ejb-relationship-role>
          <ejb-relationship-role>
            <ejb-relationship-role-name>Customer</ejb-relationship-role-name>
            <multiplicity>One</multiplicity>
            <relationship-role-source>
              <ejb-name>Customer</ejb-name>
            </relationship-role-source>
          </ejb-relationship-role>
    </ejb-relation>

    The relationship between Person and State is here:

    <ejb-relation>
          <ejb-relation-name>Person-State</ejb-relation-name>
          <ejb-relationship-role>
            <ejb-relationship-role-name>Person</ejb-relationship-role-name>
            <multiplicity>Many</multiplicity>
            <relationship-role-source>
              <ejb-name>Person</ejb-name>
            </relationship-role-source>
            <cmr-field>
              <cmr-field-name>state</cmr-field-name>
            </cmr-field>
          </ejb-relationship-role>
          <ejb-relationship-role>
            <ejb-relationship-role-name>State</ejb-relationship-role-name>
            <multiplicity>One</multiplicity>
            <relationship-role-source>
              <ejb-name>State</ejb-name>
            </relationship-role-source>
          </ejb-relationship-role>
    </ejb-relation>

    Is there anyway that the Sun ONE App Server caches the last result and just re-uses the previous result? Can I force a flush or reload some how? I have tried to accquire a new home interface though... but it didnt help.

    Many thanks for all your time.

    Best regards
    /allan
  4. Re: Sun ONE finder problems[ Go to top ]

    As a hopefully tempoary HACK, I can load all the persons into the memory and sort them by comparing their customerId to the customer's id.

    But this sucks big time! Has anyone else a possible solution?

    Best regards
    Allan
  5. Re: Sun ONE finder problems[ Go to top ]

    I found this at sun.com:

    http://softwareforum.sun.com/NASApp/jive/thread.jsp?forum=58&thread=15855

    Does anyone know more about this bug or how to fix it?

    /Allan Lauridsen
  6. Re: Sun ONE finder problems[ Go to top ]

    It gets better. I think it is a known bug... but dont know if it has been fixed:

    http://softwareforum.sun.com/NASApp/jive/thread.jsp?forum=57&thread=15559

    Great!!! I just spend 4 working days thinking it was me who needed a brain transplantation!!!