这是在一个session bean中的一个方法: public Collection GetAllOrders() {
    /**@todo Complete this method*/
    Collection orders = null;
        try{
          Context ctx = new InitialContext();
          OrdersHome home = (OrdersHome)ctx.lookup("Orders");
          orders = home.findAll();
          Iterator it = orders.iterator();
         while(it.hasNext()){
            Orders ordersitem = (Orders)it.next();
            System.out.println("the ordersitem's orderid "+ ordersitem.getOrderid());
          }
          System.out.println("GetOrdersBean's GetAllOrders number is "+ orders.size());
        }
        catch(Exception ex){
            System.out.println("GetOrdersBean 's GetAllOrders error"+ex.getMessage());
        }
    return orders;
  }findAll()就不用写了吧。

解决方案 »

  1.   

    以上程序没错,EJBQL也没问题,不如试试用findByPrimaryKey()方法看看能不能查找到记录.
    关注!
      

  2.   

    没有出错信息? ------------------------------------------------------
               我们还年轻牛奶会有的奶牛也会有的 
                 可天天在 csdn 混这些会有吗 ??
      

  3.   

    问题可能出在这一句:
    OrdersHome home = (OrdersHome)ctx.lookup("Orders");看看此处home是否得到正确的返回值了(如果是空值,说明JNDI查找没有得到正确结果),
    请确认一下!