如何执行HQL?
Hibernate通过Query接口执行HQL语句,如:
Query query= session.createQuery("fromCustomer");
Iterator it = query.list().iterator();
while(it.hasNext()) {
Customer c = (Customer)it.next();
System.out.println(c.getCustomerId());
}
事实上,可以换成:
Iterator it = query.iterate();
对于前者,会一次性把所有数据都读取出来,执行语句类似:
select * from customer
而后者,则只取出对象的OID,通过OID一次只查询一个对