public static void main(String args[]){ Session session = HibernateUtil.getSessionFactory().openSession(); Query query = session.createQuery("from House"); List<House> list = query.list(); Iterator<House> it = list.iterator(); System.out.println("我运行了"); while(it.hasNext()){ House house = it.next(); System.out.println(house.getDescription()+" "+house.getTitle()); } System.out.println("我运行即将结束"); session.close(); } }
我的House里有数据的 但是运行结果 如下 Hibernate: select house0_.id as id3_, house0_.user_id as user2_3_, house0_.type_id as type3_3_, house0_.street_id as street4_3_, house0_.title as title3_, house0_.description as descript6_3_, house0_.price as price3_, house0_.pubdate as pubdate3_, house0_.adddate as adddate3_, house0_.floorage as floorage3_, house0_.contact as contact3_ from house house0_ 我运行了 我运行即将结束 ------------------------------------------------------------- 为什么迭代不出东西来呢? ------解决思路---------------------- 没有进入while循环,list为0 List<House> list = query.list(); System.out.println(list.size());//看结果是否为0