Example usage for org.hibernate.jpa QueryHints HINT_FETCH_SIZE

List of usage examples for org.hibernate.jpa QueryHints HINT_FETCH_SIZE

Introduction

In this page you can find the example usage for org.hibernate.jpa QueryHints HINT_FETCH_SIZE.

Prototype

String HINT_FETCH_SIZE

To view the source code for org.hibernate.jpa QueryHints HINT_FETCH_SIZE.

Click Source Link

Document

The hint key for specifying a JDBC fetch size, used when executing the resulting SQL.

Usage

From source file:org.mascherl.example.service.MailService.java

License:Apache License

@Transactional
public List<Mail> getMailsForUser(User currentUser, MailType mailType, int offset, int pageSize) {
    List<MailEntity> resultList = em
            .createQuery("select m " + "from MailEntity m " + "where m.user.uuid = :userUuid "
                    + "and m.mailType = :mailType " + "order by m.dateTime desc", MailEntity.class)
            .setParameter("userUuid", currentUser.getUuid()).setParameter("mailType", mailType)
            .setFirstResult(offset).setMaxResults(pageSize).setHint(QueryHints.HINT_READONLY, Boolean.TRUE)
            .setHint(QueryHints.HINT_FETCH_SIZE, pageSize).getResultList();

    return resultList.stream().map(MailConverter::convertToDomain).collect(Collectors.toList());
}