Example usage for org.hibernate.jpa HibernateQuery getHibernateQuery

List of usage examples for org.hibernate.jpa HibernateQuery getHibernateQuery

Introduction

In this page you can find the example usage for org.hibernate.jpa HibernateQuery getHibernateQuery.

Prototype

public org.hibernate.Query getHibernateQuery();

Source Link

Document

Gives access to the underlying Hibernate query object..

Usage

From source file:com.querydsl.jpa.HibernateHandler.java

License:Apache License

@SuppressWarnings("unchecked")
@Override/*ww w .j a va2 s  . com*/
public <T> CloseableIterator<T> iterate(Query query, FactoryExpression<?> projection) {
    if (query instanceof HibernateQuery) {
        HibernateQuery hQuery = (HibernateQuery) query;
        ScrollableResults results = hQuery.getHibernateQuery().scroll(ScrollMode.FORWARD_ONLY);
        CloseableIterator<T> iterator = new ScrollableResultsIterator<T>(results);
        if (projection != null) {
            iterator = new TransformingIterator<T>(iterator, projection);
        }
        return iterator;
    } else {
        Iterator<T> iterator = query.getResultList().iterator();
        if (projection != null) {
            return new TransformingIterator<T>(iterator, projection);
        } else {
            return new IteratorAdapter<T>(iterator);
        }
    }
}