FINDER METHOD in WAS 4.0

Discussions

EJB programming & troubleshooting: FINDER METHOD in WAS 4.0

  1. FINDER METHOD in WAS 4.0 (2 messages)

    I have deployed CMP bean in WAS 4.0.
    Route is my Remote interface.
    I have a findByStartEndCity in my RouteHome home interface.
    Now when i use findByStartEndCity method it give me enumeration.

    When i use the below statement
    Route bean = (Route)enum.nextElement();

    it give me the error
    java.lang.ClassCastException: org.omg.stub.javax.ejb._EJBObject_Stub

    And when i use the below statements it works fine

    java.util.Enumeration enum = routeHome.findByStartEndCity("US","CANADA");
    for (; enum.hasMoreElements() ;)
    {
        System.out.println( " Inside Loop ");
        RouteKey routekeys = (RouteKey)
             ((javax.ejb.EJBObject)enum.nextElement)).getPrimaryKey();
                  
        Route bean = routeHome.findByPrimaryKey(routekeys);
        System.out.println(bean.getFare());
    }//end of for

    Can any body tell why is it so ???????????????????????

    Thanks
    Rajan

    Threaded Messages (2)

  2. FINDER METHOD in WAS 4.0[ Go to top ]

    Hi rajan ,
      Could u pls send me the Initial context factory code coz i was working on weblogic & now i wanna try out the same thing on WAS.
    Waitting for ur positive reply.
    bye
    -kiran
  3. FINDER METHOD in WAS 4.0[ Go to top ]

    Hi kiran
    I am sending u my complete client file.
    If u coluld let me know why i am gettinf classcast exception.
    It will be great

    Rajan






    import java.io.PrintStream;
    import java.util.Hashtable;
    import java.util.Properties;
    import javax.naming.*;
    import javax.rmi.PortableRemoteObject;
    import packroute.*;

    public class RouteClient
    {
        public RouteClient()
        {
        }
        public static void main(String args[])
        {
            try
            {
                Properties props = new Properties();
                props.put("java.naming.factory.initial", "com.ibm.websphere.naming.WsnInitialContextFactory");
                props.put("java.naming.provider.url", "iiop://204.160.254.211:900");
                Context ctx = new InitialContext(props);
                Object homeObject = ctx.lookup("packroute/Route");
                System.out.println("Looked Up");
                try
                {
                 RouteHome routeHome = (RouteHome)javax.rmi.PortableRemoteObject.narrow(homeObject,RouteHome.class);
                 System.out.println("after getting home");
                 Route bean = null;
    System.out.println(" creating EJB ...");
    bean = routeHome.create(801,"CHINA",25234,"SRILANKA");
    System.out.println("startcity " + bean.getStartCity());
    RouteKey routekey = new RouteKey(8);
    bean = routeHome.findByPrimaryKey(routekey);
    System.out.println("startcity query " + bean.getEndCity());
    java.util.Enumeration enum = routeHome.findByStartEndCity("US","CANADA");

    for (; enum.hasMoreElements() ;) {
                  System.out.println( " Inside Loop ");
                  RouteKey routekeys = (RouteKey)((javax.ejb.EJBObject)enum.nextElement()).getPrimaryKey();
                  bean = routeHome.findByPrimaryKey(routekeys);
                  
                  //bean = (Route)enum.nextElement(); it should work this way
                  System.out.println(bean.getFare());

    }//end of for


                }//end of try
                catch(javax.ejb.FinderException e)
                {
                 e.printStackTrace();
                 System.out.println("FinderException.......??????????");
                }
                catch(Exception e)
                {
                 e.printStackTrace();
                }
            }
            catch(Exception ex)
            {
                System.err.println("Caught an unexpected exception!");
                ex.printStackTrace();
            }
        }
    }