@SuppressWarnings("unchecked")
    @Override
    public <T> CloseableIterator<T> iterate(Query query, FactoryExpression<?> projection) {
        boolean canUseCursor = false;
        try {
            canUseCursor = query.unwrap(Query.class) instanceof JpaQuery;
        } catch (PersistenceException e) { } // can't unwrap, just ignore the exception

        Iterator<T> iterator = null;
        Closeable closeable = null;
        if (canUseCursor) {
            query.setHint(QueryHints.CURSOR, HintValues.TRUE);
            final Cursor cursor = (Cursor) query.getSingleResult();
            final int pageSize = cursor.getPageSize();
            closeable = new Closeable() {
                @Override
                public void close() throws IOException {
                    cursor.close();
                }
            };
            iterator = new Iterator<T>() {
                private int rowsSinceLastClear = 0;

                @Override
                public boolean hasNext() {
                    return cursor.hasNext();
                }

                @Override
                public T next() {
                    if (rowsSinceLastClear++ == pageSize) {
                        rowsSinceLastClear = 0;
                        cursor.clear();
                    }
                    return (T) cursor.next();
                }
            };
        } else {
            iterator = query.getResultList().iterator();
        }
        if (projection != null) {
            return new TransformingIterator<T>(iterator, closeable, projection);
        } else {
            return new IteratorAdapter<T>(iterator, closeable);
        }
    }
{@code EclipseLinkHandler} is the {@link QueryHandler} implementation for EclipseLink

@author tiwe
querydsl-jpa/src/main/java/com/querydsl/jpa/EclipseLinkHandler.java