你的实体bean市local的,当然可以强制转换,而PortableRemoteObject是实现远程对象的转换,当然不可以了

解决方案 »

  1.   

    to liuxiao1217() :
    you are wrong! 
    this.commBookHome=(CommBookHome)PortableRemoteObject.narrow(o,CommBookHome.class);
    above is a standard invoke type,it is good.
    why does the exception occured?
    I think of that that ejb deployment package is not right, suggest the
    author to check the package carefully!
      

  2.   

    Object obj = ctx.lookup("account");
    account应该是由account.create(PRIMARYKEY);生成的. 另外你有没有定义它的jini你怎么lookup呢?
      

  3.   

    我也遇到过类似问题,先是在weblogic6.1里面(自然是盗版的),也会出现你所说的那样。
    EJB是发布成功了,因为根据JNDI可以得到Object对象,但:
    AccountHome home = (AccountHome)javax.rmi.PortableRemoteObject.narrow(obj,AccountHome.class);
    就出错!!!
    我弄了大半天没发现错误,实在气愤至极,干脆不弄了。换JBOSS试试,结果同样的代码却一切正常!
    其实你的EJB是没有问题。可能是你的接口没有放好,再或者你的EJB容器根本就没有用。
    我猜的……
      

  4.   

    在《Mastering EJB》中讲的很清楚了,但也很容易忽略。引用书中的原话:
    You can also access EJB components from other EJB components throught their local interfaces rather than their remote interface.
      

  5.   

    没那么复杂。是java.lang.NoClassDefFoundError而不是ClassCastException.同意 snowglede(雪鹰) 的看法。
      

  6.   

    同意
    没那么复杂。是java.lang.NoClassDefFoundError而不是ClassCastException.同意 snowglede(雪鹰) 的看法。