0 Replies Latest reply on Nov 18, 2004 11:21 PM by ashishabrol

    Persistence problem in JBoss

    ashishabrol Newbie

      Hi All

      I have a very serious problem and would really appreciate if anyone can help me out with this.

      The problem is a very weird one. When i call the retrieveaddress() function below i get 2 different values for the CandidateId that i am printing before and after running the Ejb-Ql. I have checked the database and it is correct

      After running the query it should go to that particular candidateID but it returns me a different candidateID and the worst part of it is that this happens only sometimes.

      Most of the times it gives me correct values. But sometimes it returns me the candidateID of the candidate on whom this function has previously been called already. Suppose when I call this function for candidateID 255 it will display correct candidateID after running ejb-QL but when I call this function for some other candidate say 244 it displays me the values of the candidate 255. It looks as if there is some persistence problem. But I am not able to figure out what the problem is.

      public void retrieveAddress(Long candidateID, Long addressSequence) throws NamingException,FinderException
       {
       CandidateAddLocal candidateAddLocal;
       try{
       CandidateAddLocalHome candidateAdd;
       candidateAdd = this.getESPCandidateAddLocalHome();
      
       System.out.println("candidateID before the EJB-Ql=" + candidateID);
       Vector collection = new Vector (candidateAdd.findbyCandidateId(candidateID, addressSequence));
       Iterator iterator = collection.iterator();
       while (iterator.hasNext())
       {
       candidateAddLocal = (CandidateAddLocal)iterator.next();
       System.out.println("candidateID after the EJB-Ql=" + candidateAddLocal.getCandidateId());
       }
       }
       catch (NamingException ne) {System.out.println("NamingException");ne.printStackTrace();}
       catch(Throwable e){
       e.printStackTrace();
       }
       }
      
      private CandidateAddLocalHome getCandidateAddLocalHome() throws NamingException
       {
       final javax.naming.InitialContext context = new javax.naming.InitialContext();
       return (CandidateAddLocalHome)context.lookup("java:comp/env/ejb/local/CandidateAdd");
       }



      In ejb-jar.xml I Have Defined The ejb-ql In The Following Manner-


      <query-method>
      <method-name>findbyCandidateId</method-name>
      <method-params>
      <method-param>java.lang.Long</method-param>
      <method-param>java.lang.Long</method-param>
      </method-params>
      </query-method>
      <ejb-ql>SELECT OBJECT(i) FROM CandidateAdd AS i where i.candidateId = ?1 and i.addressSequence = ?2</ejb-ql>



      And In The CandidateAddLocalHome CMP I Have Declared The Fucntion In The Following Manner-

      Collection findbyCandidateId(Long candidateId, Long addressSequence) throws FinderException;