可能是你sql错了, 修改一下catch部分:catch (Exception ex) {
      throw new DAOException("Query the FirstLevelProjectIte occur errors:", ex);
    }==>catch (Exception ex) {
      ex.printStackTrace();
    }

解决方案 »

  1.   

    java.lang.UnsupportedOperationException: SQL queries do not currently support iteration
    简单翻译一下:
    ‘java.lang.UnsupportedOperationException: Sql查询目前不支持iteration’
      

  2.   

    哦, 你用的是原生sql查询。 你还是用list吧。
      

  3.   

    試試下面是否可以? 
    public Iterator FirstLevelProjectIte() throws DAOException {
        Iterator firstLevelProjectIte = null;
        try {
          firstLevelProjectIte = session.createSQLQuery(
                  " select {p.*},{t.*}" +
                  " from project {p},task {t} " +
                  " where {p}.id={t}.project_id ", new String[] {"p", "t"},
                  new Class[] {Project.class, Task.class}).list().iterator();
          return firstLevelProjectIte;
        } catch (Exception ex) {
          throw new DAOException("Query the FirstLevelProjectIte occur errors:", ex);
        }
      }
     
    public static void main(String[] args) throws DAOException,
              HibernateException {
        ProjectDAO dao = new HibernateProjectDAOImpl();
            Iterator ite = dao.FirstLevelProjectIte();     if (ite.hasNext()) {
              Object[] o = (Object[]) ite.next();
          for (int i = 0; i < o.length; i++) {
     
            Project project = null;
     
            try {
              project = dao.findByPK(2);
                 if (o[i].equals(project)) {
                   System.out.println("obj:" + project.getDescription());
                 }
            } catch (DAOException ex) {
                ex.printStackTrace();
            } catch (DataNotFoundException ex) {
                 ex.printStackTrace();
            }
          }
        }
      }