Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hibernate version: 3.3.1
Actually, criteria querys return results of the type ScrollableResults, while HQL querys return an standard java Iterator. The problem, is that it makes difficult to change from criteria to query without changing the interface, as data types returned are different. Adding Iterator support to Criteria, should be as easy as wrapping ScrollableResult in an Iterator implementation, and it would allow to return an Iterator with both HQL and Criteria.
Code:
public class ScrollableResultsIteratorImpl implements Iterator {
public ScrollableResultsIteratorImpl(ScrollableResults scrollableResult) {
this.scrollableResult = scrollableResult;
}
private ScrollableResults scrollableResult = null;
public boolean hasNext() {
return !scrollableResult.isLast();
}
public Object next() {
scrollableResult.next();
return scrollableResult.get();
}
@Override
public void remove() {
throw new UnsupportedOperationException("remove not supported");
}
}
And just add an iterate() method to CriteriaImpl
Code:
public Iterator iterate() {
return new ScrollableResultsIteratorImpl(scroll(ScrollMode.FORWARD_ONLY));
}