服务器端:Product.java ProductHome.java ProductBean.java 
客户端:ProductClient.java

解决方案 »

  1.   

    这是客户端程序ProductClient.java
    运行到Iterator i = home.findByName("SD-64").iterator();就出错
          
    import javax.ejb.*;
    import javax.naming.*;
    import java.rmi.*;
    import javax.rmi.PortableRemoteObject;
    import java.util.*;/**
     * CMP实体bean--Product的客户端测试应用
     */
    public class ProductClient 
    {  public static void main(String[] args) throws Exception 
      {    ProductHome home = null;  try 
        {
          /*
           * 获得产品Home对象引用,即产品EJB对象工厂
           */
          Properties props = System.getProperties();
          props.setProperty("java.naming.factory.initial","org.jnp.interfaces.NamingContextFactory");
          props.setProperty("java.naming.factory.url.pkgs","org.jboss.naming:org.jnp.interfaces");
          props.setProperty("java.naming.provider.url","jnp://localhost");
         
         System.out.println("88888888888888888888");
         
          Context ctx = new InitialContext(props); //这些属性将从命令行读出
          home = (ProductHome) PortableRemoteObject.narrow(
            ctx.lookup("ProductHome"), ProductHome.class);      /*
           * 使用工厂创建产品EJB对象
           */
          home.create("123-456-7890", "P5-350", "350 Mhz Pentium", 200);
          home.create("123-456-7891", "P5-400", "400 Mhz Pentium", 300);
          home.create("123-456-7892", "P5-450", "450 Mhz Pentium", 400);
          home.create("123-456-7893", "SD-64", "64 MB SDRAM", 50);
          home.create("123-456-7894", "SD-128", "128 MB SDRAM", 100);
          home.create("123-456-7895", "SD-256", "256 MB SDRAM", 200);      /*
           * 找到一个产品,并输出它的描述
           */
           
        
          Iterator i = home.findByName("SD-64").iterator();
          System.out.println("These products match the name SD-64:");
          while (i.hasNext()) 
           {
            Product prod = (Product) PortableRemoteObject.narrow(i.next(), Product.class);
            System.out.println(prod.getDescription());
           }
        
           
          /*
           * 找到成本为$200的产品
           */
          System.out.println("Finding all products that cost $200");
           i = home.findByBasePrice(200).iterator();      while (i.hasNext()) 
          {
            Product prod = (Product) PortableRemoteObject.narrow(i.next(), Product.class);
            System.out.println(prod.getDescription());
          }
        }
     catch (Exception e) 
     {
      e.printStackTrace();
     }
     finally 
      {
          if (home != null) 
        {
            System.out.println("Destroying products..");        /*
             * 找到所有的产品
             */
            Iterator i = home.findAllProducts().iterator();
            while (i.hasNext()) 
           {
              try 
              {
                Product prod = (Product) PortableRemoteObject.narrow(i.next(), Product.class);
                if (prod.getProductID().startsWith("123")) 
                {
                  prod.remove();
                }
              }
              catch (Exception e) 
              {
                e.printStackTrace();
              }
            }
          
          }
        }
        
      }
    }
      

  2.   

    应该不是client的错!看看你findByName的返回类型。
      

  3.   

    to: funpig(麻子):findByName返回一个集合
    是不是部署文件有问题啊?
    import javax.ejb.*;
    import java.rmi.RemoteException;
    import java.util.Collection;public interface ProductHome extends EJBHome 
    { Product create(String productID, String name, String description, double basePrice) 
                    throws CreateException, RemoteException; // Finder方法,他们被容器实现。
    // 你能够通过EJB-QL和容器工具在部署描述符内定制这些方法的功能。
    public Product findByPrimaryKey(String key) 
                    throws FinderException, RemoteException; public Collection findByName(String name) 
                    throws FinderException, RemoteException; public Collection findByDescription(String description) 
                    throws FinderException, RemoteException; public Collection findByBasePrice(double basePrice) 
                    throws FinderException, RemoteException; public Collection findExpensiveProducts(double minPrice) 
                    throws FinderException, RemoteException; public Collection findCheapProducts(double maxPrice) 
                     throws FinderException, RemoteException; public Collection findAllProducts() 
                     throws FinderException, RemoteException;
    }
      

  4.   

    把你的整个配置文件copy出来看看,可能试那个ql语句的问题@