可能是你sql错了, 修改一下catch部分:catch (Exception ex) {
throw new DAOException("Query the FirstLevelProjectIte occur errors:", ex);
}==>catch (Exception ex) {
ex.printStackTrace();
}
throw new DAOException("Query the FirstLevelProjectIte occur errors:", ex);
}==>catch (Exception ex) {
ex.printStackTrace();
}
简单翻译一下:
‘java.lang.UnsupportedOperationException: Sql查询目前不支持iteration’
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();
}
}
}
}