3 Replies Latest reply on Sep 23, 2003 2:10 AM by nraghuram

    Problem with finder method in CMP2.0

    teena Newbie

      Hi All,
      I am new to JBOSS 3.2 environment and am experiencing problem in implementing the CMP2.0 beans. Though all the getter/setter methods of my CMP bean work properly, I am unable to get the finder methods to work. My client hangs when calling the finder methods of my CMP bean. Only the findByPrimaryKey is working properly. However, I have provided the ejbql for the custom finder methods.

      I have also provided a sample of my ejb-jar.xml file for your reference. please let me know if I have to do any changes in ejb-jar.xml or the jbosscmp-jdbc.xml to make my code function.

      <ejb-jar>
      JBoss Employee Sample Application
      <display-name>EmployeeEJB</display-name>
      <enterprise-beans>

      <ejb-name>EmployeeBean</ejb-name>
      <local-home>ejb.EmployeeLocalHome</local-home>
      ejb.EmployeeLocal
      <ejb-class>ejb.EmployeeBean</ejb-class>
      <persistence-type>Container</persistence-type>
      <prim-key-class>java.lang.String</prim-key-class>
      False

      <cmp-version>2.x</cmp-version>
      <abstract-schema-name>EmployeeBean</abstract-schema-name>

      <cmp-field><field-name>empNo</field-name></cmp-field>
      <cmp-field><field-name>empName</field-name></cmp-field>
      <primkey-field>empNo</primkey-field>

      <!---probably here lies the problem-->
      <query-method>
      <method-name>findByEmpName</method-name>
      <method-params>
      <method-param>java.lang.String</method-param>
      </method-params>
      </query-method>
      <ejb-ql>
      <![CDATA[SELECT OBJECT(e) FROM EmployeeBean AS e WHERE e.empName = ?1]]>
      </ejb-ql>


      </enterprise-beans>
      <!--....assembly descriptor...follows....-->
      </ejb-jar>

      here follows the extract of my jbosscmp-jdbc.xml file

      <enterprise-beans>

      <ejb-name>EmployeeBean</ejb-name>

      java:/LibraryDS
      <datasource-mapping>Oracle8</datasource-mapping>

      <create-table>true</create-table>
      <remove-table>true</remove-table>

      <table-name>EmployeeEJB</table-name>

      <cmp-field>
      <field-name>empNo</field-name>
      <column-name>empno</column-name>
      </cmp-field>
      <cmp-field>
      <field-name>empName</field-name>
      <column-name>empname</column-name>
      </cmp-field>

      </enterprise-beans>

      Eagerly waiting for any response.

      Thanks,
      Teena

        • 1. Re: Problem with finder method in CMP2.0
          Adrian Brock Master

          Where does it "hang" post a thread dump.

          Regards,
          Adrian

          • 2. Re: Problem with finder method in CMP2.0
            teena Newbie

            Adrian,

            Thanks for the response.
            For debugging purposes, I have put some log statements inside my servlet's post method. Here is the extract of that.

            EmployeeLocal duke = employeeHome.create(101, "Duke","6th street","London","UK","7th","NY","US","","","");
            System.out.println(duke.getEname()+" created with id= "+duke.getEID());
            duke.setEname("Robin");
            System.out.println("His changed Name is "+duke.getEname());

            EmployeeLocal john = employeeHome.create(102, "john");
            System.out.println(john.getEname()+" created with id= "+john.getEID());

            EmployeeLocal duke1=employeeHome.findByPrimaryKey(new EmployeePK(101));
            EmployeeLocal john1=employeeHome.findByPrimaryKey(new EmployeePK(102));
            System.out.println("Getting List");
            ArrayList arl=duke1.getAddressList();
            System.out.println("Got List");
            Iterator i=arl.iterator();
            int j=0;
            while (i.hasNext()) {
            try{
            AddressLocal addr=(AddressLocal)arl.get(j);
            System.out.println(addr.getCity());
            }catch(Exception e){
            break;
            }
            j++;
            }
            System.out.println("Looking out for Robins");
            Collection c1=employeeHome.findByEname("Robin");
            Iterator i1=c1.iterator();
            int j1=0;
            while(i1.hasNext()){
            j1++;
            }
            System.out.println("We have "+j1+" Robins");

            Collection c2=employeeHome.findAll();
            Iterator i2=c2.iterator();
            int j2=0;
            while(i2.hasNext()){
            j2++;
            }
            System.out.println("We have "+j2+" Employees");




            So, when I run this servlet,here is what I get at the prompt.

            13:40:05,004 INFO [STDOUT] Lookup for EmployeeDetails is success
            13:40:05,164 INFO [STDOUT] Duke created with id= 101
            13:40:05,284 INFO [STDOUT] His changed Name is Robin
            13:40:05,344 INFO [STDOUT] john created with id= 102
            13:40:05,364 INFO [STDOUT] Getting List
            13:40:05,384 INFO [STDOUT] Got List
            13:40:05,434 INFO [STDOUT] London
            13:40:05,444 INFO [STDOUT] NY
            13:40:05,474 INFO [STDOUT] null
            13:40:05,474 INFO [STDOUT] Looking out for Robins

            Just after it says 'Looking out for Robins' it hangs, when executing findByEname. However, it doesn't throw any exceptions. One more peculiar behaviour is that it executes perfectly if no matching bean is found.

            also, I have changed the xmls that I had earlier posted. Here is the new version of it.

            <ejb-jar>
            <enterprise-beans>

            <ejb-name>EmployeeEJB</ejb-name>
            <local-home>DataServices.Entity.EmployeeLocalHome</local-home>
            DataServices.Entity.EmployeeLocal
            <ejb-class>DataServices.Entity.EmployeeEJB</ejb-class>
            <persistence-type>Container</persistence-type>
            <prim-key-class>DataServices.Entity.EmployeePK</prim-key-class>
            False
            <cmp-version>2.x</cmp-version>
            <abstract-schema-name>EmployeeEJB</abstract-schema-name>
            <cmp-field><field-name>eID</field-name></cmp-field>
            <cmp-field><field-name>ename</field-name></cmp-field>

            <query-method>
            <method-name>findByEname</method-name>
            <method-params>
            <method-param>java.lang.String</method-param>
            </method-params>
            </query-method>
            <ejb-ql>
            <![CDATA[SELECT OBJECT(e) FROM EmployeeEJB e WHERE e.ename = ?1]]>
            </ejb-ql>


            <query-method>
            <method-name>findAll</method-name>
            <method-params/>
            </query-method>
            <ejb-ql>
            <![CDATA[SELECT OBJECT(e) FROM EmployeeEJB e]]>
            </ejb-ql>



            <ejb-name>AddressEJB</ejb-name>
            <local-home>DataServices.Entity.AddressLocalHome</local-home>
            DataServices.Entity.AddressLocal
            <ejb-class>DataServices.Entity.AddressEJB</ejb-class>
            <persistence-type>Container</persistence-type>
            <prim-key-class>DataServices.Entity.AddressPK</prim-key-class>
            False
            <cmp-version>2.x</cmp-version>
            <abstract-schema-name>AddressEJB</abstract-schema-name>
            <cmp-field><field-name>eID</field-name></cmp-field>
            <cmp-field><field-name>aID</field-name></cmp-field>
            <cmp-field><field-name>street</field-name></cmp-field>
            <cmp-field><field-name>city</field-name></cmp-field>
            <cmp-field><field-name>country</field-name></cmp-field>

            </enterprise-beans>


            <ejb-relation>
            <ejb-relation-name>Employee-Address</ejb-relation-name>

            <ejb-relationship-role>
            <ejb-relationship-role-name>Employee-has-Addresses</ejb-relationship-role-name>

            One

            <relationship-role-source>
            <ejb-name>EmployeeEJB</ejb-name>
            </relationship-role-source>

            <cmr-field>
            <cmr-field-name>addresses</cmr-field-name>
            <cmr-field-type>java.util.Collection</cmr-field-type>
            </cmr-field>
            </ejb-relationship-role>

            <ejb-relationship-role>
            <ejb-relationship-role-name>Addresses-belongs-to-Employee</ejb-relationship-role-name>

            Many

            <relationship-role-source>
            <ejb-name>AddressEJB</ejb-name>
            </relationship-role-source>
            </ejb-relationship-role>
            </ejb-relation>

            <assembly-descriptor>
            <container-transaction>

            All methods require a transaction


            <ejb-name>EmployeeEJB</ejb-name>
            <method-name>*</method-name>

            <trans-attribute>Required</trans-attribute>
            </container-transaction>
            </assembly-descriptor>
            </ejb-jar>

            A small Export of jboss-cmp.xml follows

            <enterprise-beans>

            <ejb-name>EmployeeEJB</ejb-name>

            java:/LibraryDS
            <datasource-mapping>Oracle8</datasource-mapping>

            <create-table>true</create-table>
            <remove-table>true</remove-table>

            <table-name>EmployeeEJB</table-name>
            <cmp-field>
            <field-name>eID</field-name>
            <column-name>eID</column-name>
            </cmp-field>
            <cmp-field>
            <field-name>ename</field-name>
            <column-name>ename</column-name>
            </cmp-field>



            <ejb-name>AddressEJB</ejb-name>

            java:/LibraryDS
            <datasource-mapping>Oracle8</datasource-mapping>

            <create-table>true</create-table>
            <remove-table>true</remove-table>

            <table-name>AddressEJB</table-name>
            <cmp-field>
            <field-name>eID</field-name>
            <column-name>eID</column-name>
            </cmp-field>
            <cmp-field>
            <field-name>aID</field-name>
            <column-name>aID</column-name>
            </cmp-field>
            <cmp-field>
            <field-name>street</field-name>
            <column-name>street</column-name>
            </cmp-field>
            <cmp-field>
            <field-name>city</field-name>
            <column-name>city</column-name>
            </cmp-field>
            <cmp-field>
            <field-name>country</field-name>
            <column-name>country</column-name>
            </cmp-field>

            </enterprise-beans>



            Thanks for your time.
            Please give me your views and hence the possible solution to my problem.

            Thanks and Regards,
            Teena

            • 3. Re: Problem with finder method in CMP2.0
              nraghuram Newbie

              Your iterator loop is not ending bcos you arent calling iterator.next();