Collection接口不能执行序列化,它无法在网络中(不同的jvm中)传递
你必须用其他方法来封装需要传递的数据。

解决方案 »

  1.   

    Enumeration好像是Jdk1.0里面的一个老式序列化接口吧,恳请做过SessionBean调用CMP中查找方法的大虾们指点~~~
      

  2.   

    可以用jb自动生成的sessionfacade,它会自动把cmp的findby返回的集合包裹成为一个对象数组,然后从session bean中返回给客户端,这样在客户端调用就应该没有问题了
      

  3.   

    在Collection col=pro.findByXx(xx);前面加上
    Collection col=new ArrayList();
      

  4.   

    sorry!!!写错了,
    应该是Collection col1=new ArrayList();
    然后再把col里的值放到col1中,return col1;
      
      

  5.   

    好像也不行,coll.addAll(col)是不是这样放进去的~
    楼上那位大哥不是说在JBuilder里面自动生成sessionfacade,能不能说得详细点,谢谢~!
      

  6.   

    如果你使用jb开发,在servlet里面调用,我教你:)
      

  7.   

    问题1:
     CMP作为"Remote"接口,定义"findByXx()"方法后编译出错,但改为"Local"接口编译部署就可以了,是不是CMP中的"findByXx()"方法不支持远程调用;
     我可以保证CMP的findByXx()肯定.支持
    1. classHome接口必须是Remote
    2.findByXX()throw xxx.Remote接口
    3.classBean中findByXX()throw xxx.Remote
    3.看配置文件为Remote
    <remote>classHome</remote>
    <remote>classBean</remote>
    ................问题2:
     SessionBean调用CMP的"findByXx()",再用客户端调用SessionBean的时,运行客户端无结果,代码如下:
    Product pro;//Product为CMP接口;
    SessionBean中调用CMP的"findByXx()"代码:
    Collection col=null; 
    public java.util.Collection queryByXx(java.lang.String xx){
       try{
         Collection col=pro.findByXx(xx);
       }catch(Exception e){}
       return col;
     }
    客户端调用SessionBean中的"queryByXx()"代码:
     Collection col=manage.queryByXx(xx);
     Iterator itr=col.iterator();
     while(itr.hasNext()){
      Product pro=(Product)itr.next();
      System.out.println(pro.getXx()); 
     }
    改为:
    在问题1必须解决使有该方法你可是client调用呀,必须用远程接口
    客户端调用SessionBean中的"queryByXx()"代码:
     Collection col=manage.queryByXx(xx);
     Iterator itr=col.iterator();
     while(itr.hasNext()){
      Product pro=(Product)javax.rmi.PortableObject.narrow(itr.next(),Product.class));
      System.out.println(pro.getXx()); 
     }
      

  8.   

    楼上的大哥,你说的方法还是不行,问题不在“Product pro=(Product)java.rmi.PortableRemoteObject.narrow(itr.next,Product.class));
    小弟再演示下我的代码:
    SessionBean:queryByXx():
    public java.util.Collection queryByXx(java.lang.String xx){
     try{
      Collection col=proHome.findByXx(xx);//proHome为CMP的Home接口 
      System.out.println("col.size() : "+col.size());//测试"col"是否有数据,本例中有数据
      return col;
     }catch(Exception e){
      return null;
    }
    }
    Client:
    Collection col=SesssionBean.queryByXx(xx);
    System.out.println("Test Success");//不知为什么,把这条语句放在Col前面肯定是没问题的,但要是放在他后面就不显示结果,也就意味着之后的语句都没有执行
    System.out.println("Client col.size() : "+col.size());//没显示
    Iterator itr=col.iterator();
    while(itr.hasNext()){
     Product p=(Product)PortableRemoteObject(itr.next(),Product.class);
     System.out.println(p.getXx()+" "+p.getXxx());
    }
    本程序在SessionBean中测试结果显示正常,可以排除其他代码出问题的可能性,恳请各位再帮忙看看~!
      

  9.   

    Collection col=SesssionBean.queryByXx(xx);
    改为:
    Collection col=(Collection )SesssionBean.queryByXx(xx); try!
      

  10.   

    Collection col=SesssionBean.queryByXx(xx);
    System.out.println("Test Success");//不知为什么,把这条语句放在Col前面肯定是没问题的,但要是放在他后面就不显示结果,也就意味着之后的语句都没有执行
    在执行Collection col=SesssionBean.queryByXx(xx);
    之后抛异常了么
      

  11.   

    我的问题和你差不多.
    我有点奇怪.
    CMP作为LOCAL接口.在对话BEAN作为返回,那么就要在JSP中进行调用此CMP.
    那不变成JSP可以调用LOCAL的CMP?????
    这道理说不上去,谁能解释下
      

  12.   

    也可以实现,如将jar保和war包打入ear包中,
    但我不退间这种模式,还是在session中完成
    调用cmp(local),同时session将数据放入
    dto中放回
      

  13.   

    请楼主贴一下你的代码,客户端调用SessionBean之前,是如何初始化SessionBean的
      

  14.   

    berl88(berl) :   我也来说两句,你这样会出错的,在会话bean调用cmp返回时应该把数据封装一下再返回,这样就没问题的,你用一下jbuilder就知,它会报错的
      

  15.   

    请问各位用的是什么方法解决SessionBean调用CMP中的查找方法的呢?
      

  16.   

    你可以这样啊,在SessionBean中定义一个Collection的成员变量,定义返回Collection的成员变量的远程方法,将cmp中find方法返回的Collection遍历之后一个一个的写入Collection的成员变量,然后里在客户端就可以用调用Collection的成员变量的远程方法来获取