2 Replies Latest reply on Sep 29, 2004 5:38 PM by Frank Langelage

    Dramatically inefficient CMP engine behaviour???

    berserksangr Newbie

      environment: JBoss 3.2.4/PostgreSQL

      I have a CMP 2.0 entity bean DefinedTransfer with 6 fields. It is accessed by a container-managed relation from other bean:

      Client -----has 1..n-----> DefinedTransfer.

      But strange things happen to CMP engine when I try to query all defined transfers by a code below. Please look at the log provided in the attachements - the every entity's record in database is processed field-after field by 6 different SELECTs... The same thing is when there is more than 1 definedtransfer - read-ahead="on-load" executes this block once for different N-times OR-ed IDs, while read-ahead="none" runs this block N times.

      WHY, the fields should be read all at once!!!
      Please, give me a hint what am I doing wrong, how to fix this...

      The code:

      <somewhere in SessionBean>
      Set transfersSet = processedClientLocal.getDefinedTransfers();
      Iterator it = transfersSet.iterator();
      while (it.hasNext()) {
      createdSet.add(((DefinedTransferLocal)it.next()).createDTO());
      }


      Attached (NOTE standardjbosscmp-jdbc.xml exactly the same as shipped in the 3.2.4's default server):

      1. CMP engine query log
      2. DefinedTransfer's jbosscmp-jdbc.xml section
      3. Client's jbosscmp-jdbc.xml section
      4. Relation declaration


      -----------------------------------------------------------
      1. CMP engine query log
      -----------------------------------------------------------

      afterBegin()
      getDefinedTransfersList()
      Executing SQL: SELECT NAME, SURNAME, ADDRESSSTREET, ADDRESSHOUSE, ADDRESSFLAT, ADDRESSCITY, ADDRESSPOSTALCODE, CONTACTTEL, CONTACTEMAIL, CLIENTPASSWORD FROM clients WHERE (CLIENTID=?)
      ejbLoad()
      load relation SQL: SELECT TRANSFERID FROM definedtransfers WHERE (clientid_fk=?)
      ejbLoad()
      Executing SQL: SELECT NAME FROM definedtransfers WHERE (TRANSFERID=?)
      Executing SQL: SELECT DESCRIPTION FROM definedtransfers WHERE (TRANSFERID=?)
      Executing SQL: SELECT RECEIVERACCOUNTID FROM definedtransfers WHERE (TRANSFERID=?)
      Executing SQL: SELECT RECEIVERNAME FROM definedtransfers WHERE (TRANSFERID=?)
      Executing SQL: SELECT RECEIVERADDRESS FROM definedtransfers WHERE (TRANSFERID=?)
      beforeCompletion()
      afterCompletion()


      -----------------------------------------------------------
      2. DefinedTransfer's jbosscmp-jdbc.xml section
      -----------------------------------------------------------

      <ejb-name>DefinedTransfer</ejb-name>
      <table-name>DEFINEDTRANSFERS</table-name>
      <cmp-field>
      <field-name>transferId</field-name>
      <column-name>TRANSFERID</column-name>
      </cmp-field>
      <cmp-field>
      <field-name>name</field-name>
      <column-name>NAME</column-name>
      </cmp-field>
      <cmp-field>
      <field-name>description</field-name>
      <column-name>DESCRIPTION</column-name>
      </cmp-field>
      <cmp-field>
      <field-name>receiverAccountId</field-name>
      <column-name>RECEIVERACCOUNTID</column-name>
      </cmp-field>
      <cmp-field>
      <field-name>receiverName</field-name>
      <column-name>RECEIVERNAME</column-name>
      </cmp-field>
      <cmp-field>
      <field-name>receiverAddress</field-name>
      <column-name>RECEIVERADDRESS</column-name>
      </cmp-field>


      -----------------------------------------------------------
      3. Client's jbosscmp-jdbc.xml
      -----------------------------------------------------------

      <ejb-name>Client</ejb-name>
      <table-name>CLIENTS</table-name>
      <cmp-field>
      <field-name>clientId</field-name>
      <column-name>CLIENTID</column-name>
      </cmp-field>
      <cmp-field>
      <field-name>name</field-name>
      <column-name>NAME</column-name>
      </cmp-field>
      <cmp-field>
      <field-name>surname</field-name>
      <column-name>SURNAME</column-name>
      </cmp-field>
      <cmp-field>
      <field-name>addressStreet</field-name>
      <column-name>ADDRESSSTREET</column-name>
      </cmp-field>
      <cmp-field>
      <field-name>addressHouse</field-name>
      <column-name>ADDRESSHOUSE</column-name>
      </cmp-field>
      <cmp-field>
      <field-name>addressFlat</field-name>
      <column-name>ADDRESSFLAT</column-name>
      </cmp-field>
      <cmp-field>
      <field-name>addressCity</field-name>
      <column-name>ADDRESSCITY</column-name>
      </cmp-field>
      <cmp-field>
      <field-name>addressPostalCode</field-name>
      <column-name>ADDRESSPOSTALCODE</column-name>
      </cmp-field>
      <cmp-field>
      <field-name>contactTel</field-name>
      <column-name>CONTACTTEL</column-name>
      </cmp-field>
      <cmp-field>
      <field-name>contactEmail</field-name>
      <column-name>CONTACTEMAIL</column-name>
      </cmp-field>
      <cmp-field>
      <field-name>clientPassword</field-name>
      <column-name>CLIENTPASSWORD</column-name>
      </cmp-field>



      -----------------------------------------------------------
      4. Relation declaration
      -----------------------------------------------------------

      ejb-jar.xml:



      <ejb-relation >
      <ejb-relation-name>client-definedTransfer</ejb-relation-name>

      <ejb-relationship-role >
      <ejb-relationship-role-name>client-has-definedTransfer</ejb-relationship-role-name>
      One
      <relationship-role-source >
      <ejb-name>Client</ejb-name>
      </relationship-role-source>
      <cmr-field >
      <cmr-field-name>definedTransfers</cmr-field-name>
      <cmr-field-type>java.util.Set</cmr-field-type>
      </cmr-field>
      </ejb-relationship-role>

      <ejb-relationship-role >
      <ejb-relationship-role-name>definedTransfer-belongs_to-client</ejb-relationship-role-name>
      Many
      <cascade-delete/>
      <relationship-role-source >
      <ejb-name>DefinedTransfer</ejb-name>
      </relationship-role-source>
      </ejb-relationship-role>
      </ejb-relation>


      ----------------------------------------------------------


      jbosscmp-jdbcxml:

      <ejb-relation>
      <ejb-relation-name>client-definedTransfer</ejb-relation-name>

      <ejb-relationship-role>
      <ejb-relationship-role-name>client-has-definedTransfer</ejb-relationship-role-name>
      <key-fields>
      <key-field>
      <field-name>clientId</field-name>
      <column-name>clientid_fk</column-name>
      </key-field>
      </key-fields>
      </ejb-relationship-role>
      <ejb-relationship-role> <ejb-relationship-role-name>definedTransfer-belongs_to-client</ejb-relationship-role-name>
      <key-fields/>
      </ejb-relationship-role>
      </ejb-relation>