5 Replies Latest reply on Jul 19, 2002 12:48 PM by Alexandre

    writing your own finders in CMP Bean

    imran Newbie

      I have to write a finder in a CMPBean.
      the signatures are ;
      in HomeInterface-
      public Collection findByCategoryAndWorkGroup(long categoryid, long workgroupid)
      throws FinderException,RemoteException;

      and in bean


      public Collection ejbFindByCategoryAndWorkGroup(long categoryid, long workgroupid)
      throws FinderException
      {
      System.out.println("Starting ejbFindByCategoryAndWorkGroup");
      ........
      ........

      }

      The strange thing is it doesent even call the system.out.println and i am getting an empty collection.
      It doesent throw any exception when i call thru a test class...

      Can someone help me here please..?

        • 1. Re: writing your own finders in CMP Bean
          imran Newbie

          I forgot to mention one thing, that there is a reason for not using jaws.xml as the querry is very complex and these fields are not even in the table of the bean..

          regards

          Imran

          • 2. Re: writing your own finders in  BMP Entity Bean
            Shailesh Dangi Newbie

            --JBoss 3.0 + Tomcat 4.0 on NT--

            I ran into a similar problem for an entity bean with BMP.
            The findByPrimaryKey works fine. But with custom finder methods the bean implementation is not even called.

            Here are sample snippets of the code:

            public interface FwkTabHome extends EJBHome {
            public FwkTab create(Integer pkId, Integer orgId) throws RemoteException, CreateException;
            //This works fine
            public FwkTab findByPrimaryKey(FwkTabPK primaryKey) throws FinderException, RemoteException;
            //This doesn't
            public Collection findByAllAncestors(FwkTabPK primaryKey) throws FinderException, RemoteException;
            }


            Section of FwkBean
            .
            .
            public Collection ejbFindByAllAncestors(FwkTabPK primaryKey) throws FinderException, RemoteException{
            PreparedStatement ps = null;
            ResultSet rs = null;
            Connection conn = null;
            Vector v = new Vector();
            try{
            conn = this.getConnection();
            //This statement is not even printed in the log
            System.out.println("Connection in ejbFindAllAncestors :" + conn.getMetaData().getDriverName());
            if (conn != null)
            ps = conn.prepareStatement(" select ftb_tab_id from fwk_tabs "+
            " start with ftb_tab_id = ? "+
            " and org_id = ? " +
            " connect by prior ftb_parent_id = ftb_tab_id " +
            " and org_id = ? " +
            " order by ftb_level asc");
            if (ps != null){
            ps.setInt(1,primaryKey.getFtbTabId().intValue());
            ps.setInt(2,primaryKey.getOrgId().intValue());
            rs = ps.executeQuery();
            }
            if (rs == null)
            throw new EJBException("Error extracting resultset in ejbFindAllAncestors");

            while(rs.next()){
            FwkTabPK pk = new FwkTabPK((Integer)rs.getObject("ftb_tab_id"), primaryKey.getOrgId());
            System.out.println("Object added: " + pk.toString());
            v.addElement(pk);
            }
            }catch(java.sql.SQLException sqlEx){
            throw new EJBException("Error in finder method", sqlEx);
            }finally{
            try{
            if (rs != null)
            rs.close();
            if (ps != null)
            ps.close();
            if (conn != null)
            conn.close();
            }catch(Exception e){
            e.printStackTrace();
            }
            }
            return v;
            }
            .
            .
            .
            Do I have to add this custom finder method in some property file for JBoss to pick up?
            Moreover, while deploying, the deployment tool (autodeployer??) DOESNOT complain if find method in home interface throws different exceptions from the ejbFind method in the entity bean class. Shouldn't that be checked at the time of deployment also?

            Thanks

            • 3. Re: writing your own finders in CMP Bean
              Jeroen Vos Newbie

              I have exactly the same problem, I use JBoss 2.4.4, is there already a solution?

              • 4. Re: writing your own finders in CMP Bean
                Jeroen Vos Newbie

                I have exactly the same problem, I use JBoss 2.4.4, is there already a solution?

                • 5. Re: writing your own finders in CMP Bean
                  Alexandre Newbie

                  Hi,

                  You do not have to give any implementation for
                  your finders in case of CMP bean.
                  You just have to provide the signature in the Home of your
                  CMP and, in the DD, just write your EJB-QL that
                  represents your query.

                  Hope this helps.
                  Regards,

                  Alexandre