Query query = session.createQuery("from Person"); Iteratoriterator = query.iterate(); while(iterator.hasNext()) { Person person = iterator.next(); System.out.println(person.getName()); }
Query query = session.createQuery("select p from Person p where p.age > :age"); query.setInteger("age", 18); query.setMaxResults(50); IteratorIn order to use the org.hibernate Query iterate method, you need to have the Hibernate core library in your project. The package for this library is usually org.hibernate.iterator = query.iterate(); while(iterator.hasNext()) { Person person = iterator.next(); System.out.println(person.getName()); }