上面那样完全可以,不过      exercise1RemoteHome = (Exercise1RemoteHome)    PortableRemoteObject.narrow(ref, Exercise1RemoteHome.class);
就不需要了!

解决方案 »

  1.   

    不行啊,好像这样也会出错的啊
     ctx.lookup("Exercise");
      

  2.   

    zez你是不是误会了,我说的是怎样可以怎样寻找local home 啊,寻找remote的方法是行的
    我已经试过啦
      

  3.   

    ctx.lookup("你的JNDI Name");即可不用narrow
      

  4.   

    JNDI命一般都要以“java:/comp/env/”打头,这是规定写法,你那样写应该是找不到。
    如果是远程接口,写法又不一样。
      

  5.   

    楼上错了
    只要lookup 你的jnid名字即可 !!!
    你的那个方法只是为了避免jndi名字重名采用的一种方法,如果确定没有重名,可以不用!楼主出错,不贴出出错信息,没有人知道你哪里的错误...
    可能是你的ejb没有发布成功.也可能你的本地接口的问题..
      

  6.   

    Local Home 的Entity Bean本身是紧耦合的,所以部署时应该将Local Home 的Entity Bean与调用Bean放在一个.jar文件里面。具体应用很简单(下面的例子已经通过调试):
    假设有一个SwitchSQL实体Bean:
    //SwitchSQLBean
    import javax.ejb.*;
    import javax.ejb.*;
    public class SwitchSQLBean implements SessionBean {
      SessionContext sessionContext;
      java.lang.String originalSQL;
      java.lang.String whereSQL;
      java.lang.String[][] where = new String[9][9];
      //java.lang.String switchedSQL;
      public void ejbCreate() throws CreateException {
        /**@todo Complete this method*/
      }
      public void ejbRemove() {
        /**@todo Complete this method*/
      }
      public void ejbActivate() {
        /**@todo Complete this method*/
      }
      public void ejbPassivate() {
        /**@todo Complete this method*/
      }
      public void setSessionContext(SessionContext sessionContext) {
        this.sessionContext = sessionContext;
      }  /**get the value of the array where[i][j]*/
      public java.lang.String getWhere(int i, int j) {
        return null;
      }
      /**get the sql statement which has been modified by whereSQLS*/
      /*public java.lang.String getSwitchedSQL(String originalSQL,String flagString) {
        return originalSQL;
      }*/  /**initaialize the array where[][]*/
      public void initWhere() {  }  //get the position of the flagString such as '&1' in the originalString
      public java.lang.Integer getIndex(String flagString) {
        Integer index;
        return null;
      }
      public java.lang.String getSwitchedSQL(String originalSQL,String flagString) {
        return originalSQL;
      }
      public java.lang.String[][] getWhere() {
        return where;
      }
    }//SwitchSQLLocal
    import javax.ejb.*;
    import java.util.*;public interface SwitchSQLLocal extends javax.ejb.EJBLocalObject {
      public java.lang.String getSwitchedSQL(String originalSQL,String flagString) ;}//SwitchSQLLocalHome
    import javax.ejb.*;
    import java.util.*;
    public interface SwitchSQLLocalHome extends javax.ejb.EJBLocalHome {
      public SwitchSQLLocal create() throws CreateException;
    }部署SwitchSQL的JNDI名字为:SwitchSQLLocal   则在调用它的Bean里面引用方式为:SwitchSQLLocalHome sqlHomeObject
    SwitchSQLLocal sqlLocalObject;
    sqlHomeObject = (SwitchSQLLocalHome)ctx.lookup("SwitchSQLLocal");
    sqlLocalObject = sqlHomeObject.create();如果还有问题,可以发到我邮件:[email protected]