2 Replies Latest reply on Jun 18, 2004 9:28 AM by Darran Lofthouse

    weird problem

    ashishabrol Newbie

      hi friends I am facing a very weird problem and hope any one of u can help me out.

      Below is the structure of the Passport table:-
      PK NAME TYPE SIZE SCALE NOT NULL
      --- -------------- -------- ------- -------- -------
      Yes CANDIDATE_ID NUMBER 10 0 Yes
      No COUNTRY_ID NUMBER 3 0 No
      No PASSPORT_NO NVARCHAR2 30 No
      No PASS_ISS_DATE DATE No
      No PASS_EXP_DATE DATE No
      Yes PASS_SEQ NUMBER 3 0 Yes

      This is the data in te passport table
      CANDIDATE_ID COUNTRY_ID PASSPORT_NO PASS_ISS_DATE PASS_EXP_DATE PASS_SEQNUMBER
      ------------ --------- ----------- -------------- --------------- --------------
      1 1 a 2007-06-20 00:00:00.0 1985-01-01 00:00:00.0 0
      1 2 b 2007-06-20 00:00:00.0 1986-01-02 00:00:00.0 1
      1 3 c 2007-06-20 00:00:00.0 2006-06-03 00:00:00.0 2
      1 4 d 2007-06-20 00:00:00.0 2006-06-16 00:00:00.0 3
      ***************************************************
      These are the details of my ejb-jar.xml
      ------------------------------------------------------------------

      Entity Bean ( CMP )
      <display-name>CandidatePassport</display-name>
      <ejb-name>CandidatePassport</ejb-name>
      <local-home>com.hill_assoc.esp.CMP.CandidatePassportLocalHome</local-home>
      com.hill_assoc.esp.CMP.CandidatePassportLocal
      <ejb-class>com.hill_assoc.esp.CMP.CandidatePassportBean</ejb-class>
      <persistence-type>Container</persistence-type>
      <prim-key-class>java.lang.Long</prim-key-class>
      False
      <cmp-version>2.x</cmp-version>
      <abstract-schema-name>CandidatePassport</abstract-schema-name>
      <cmp-field>
      <field-name>candidateId</field-name>
      </cmp-field>
      <cmp-field>
      <field-name>countryId</field-name>
      </cmp-field>
      <cmp-field>
      <field-name>passportNo</field-name>
      </cmp-field>
      <cmp-field>
      <field-name>passIssDate</field-name>
      </cmp-field>
      <cmp-field>
      <field-name>passExpDate</field-name>
      </cmp-field>
      <cmp-field>
      <field-name>passSeq</field-name>
      </cmp-field>
      <primkey-field>candidateId</primkey-field>

      <query-method>
      <method-name>findAll</method-name>
      <method-params/>
      </query-method>
      <ejb-ql>select object(o) from CandidatePassport o</ejb-ql>


      <query-method>
      <method-name>findByCandidateId</method-name>
      <method-params>
      <method-param>java.lang.Long</method-param>
      </method-params>
      </query-method>
      <ejb-ql>select OBJECT(c) from CandidatePassport c where c.candidateId = ?1</ejb-ql>


      ***************************************************

      I have made a function called getPassportResultset to call the CMP --
      ----------------------------------------------------------------------------
      public Collection getPassportResultset(Long candidateID) throws NamingException, FinderException
      {
      CandidatePassportLocal candidatePassportLocal;
      Collection x = new ArrayList();
      try
      {
      CandidatePassportLocalHome candidatePassportLocalHome = this.getCandidatePassportLocalHome();
      Collection collection = candidatePassportLocalHome.findByCandidateId(candidateID);
      Iterator iterator = collection.iterator();
      while (iterator.hasNext())
      {
      System.out.println("***********************************************");
      CandidatePassportLocal candidatePassportLocal = (CandidatePassportLocal)iterator.next();
      System.out.println("getPassExpDate="+candidatePassportLocal.getPassExpDate());
      System.out.println("getCountryId()="+candidatePassportLocal.getCountryId());
      System.out.println("getPassIssDate="+candidatePassportLocal.getPassIssDate());
      System.out.println("getPassportNo="+candidatePassportLocal.getPassportNo());
      System.out.println("getPassSeq="+candidatePassportLocal.getPassSeq());
      System.out.println("---------------------------------------------------------------------");
      }
      }
      catch (NamingException ne) {System.out.println("NamingException in set CheckCandIDExistsInPassport");ne.printStackTrace();

      }
      catch (EJBException fe) {System.out.println("EJBException in set CheckCandIDExistsInPassport");fe.printStackTrace(); }
      catch(Throwable e){ e.printStackTrace(); }
      return x;
      }


      Now when I call this function getPassportResultset from the client in the following manner
      --------------------
      Collection al = new ArrayList();
      al = sessionEJBIdentity.getPassportResultset(new Long(1));

      I get this output I get. It shows me the last record 4 times. the output should have shown all the 4 records that have the candidate_id as 1 and not the last record four times.
      ----------------------------------------------------------------------------------------------------
      14:45:11,578 INFO [STDOUT] ***********************************************
      14:45:11,656 INFO [STDOUT] getPassExpDate=2006-06-16
      14:45:11,656 INFO [STDOUT] getCountryId()=4
      14:45:11,656 INFO [STDOUT] getPassIssDate=2007-06-20
      14:45:11,656 INFO [STDOUT] getPassportNo=d
      14:45:11,656 INFO [STDOUT] getPassSeq=3
      14:45:11,656 INFO [STDOUT] ---------------------------------------------------------------------
      14:45:11,656 INFO [STDOUT] ***********************************************
      14:45:11,656 INFO [STDOUT] getPassExpDate=2006-06-16
      14:45:11,656 INFO [STDOUT] getCountryId()=4
      14:45:11,656 INFO [STDOUT] getPassIssDate=2007-06-20
      14:45:11,671 INFO [STDOUT] getPassportNo=d
      14:45:11,671 INFO [STDOUT] getPassSeq=3
      14:45:11,671 INFO [STDOUT] ---------------------------------------------------------------------
      14:45:11,671 INFO [STDOUT] ***********************************************
      14:45:11,671 INFO [STDOUT] getPassExpDate=2006-06-16
      14:45:11,671 INFO [STDOUT] getCountryId()=4
      14:45:11,671 INFO [STDOUT] getPassIssDate=2007-06-20
      14:45:11,671 INFO [STDOUT] getPassportNo=d
      14:45:11,671 INFO [STDOUT] getPassSeq=3
      14:45:11,687 INFO [STDOUT] ---------------------------------------------------------------------
      14:45:11,687 INFO [STDOUT] ***********************************************
      14:45:11,687 INFO [STDOUT] getPassExpDate=2006-06-16
      14:45:11,687 INFO [STDOUT] getCountryId()=4
      14:45:11,687 INFO [STDOUT] getPassIssDate=2007-06-20
      14:45:11,687 INFO [STDOUT] getPassportNo=d
      14:45:11,687 INFO [STDOUT] getPassSeq=3
      14:45:11,687 INFO [STDOUT] ---------------------------------------------------------------------