It seems that in Jpa QueryDsl I can use paging like:
return new JPAQueryFactory(getEntityManager())
.selectFrom(entity)
.where(where_clause)
.orderBy(order_by_clause)
.offset(pageNumber * 20)
.limit(20)
.fetchResults();
Questions are:
- Is it optimal approach? Does fetchResults load only 20 elements from DB and make count query to get information about total number of entities which are in db?
- Or maybe there is some option like .page(2).limit(20)?
Yes I know that Spring-Data has already Paging and interface for QueryDsl but because of the complicated "order by" clause which is not supported by Spring-Data I cannot use it :(