I\'ve have already implemented pagination using the following code:
public Paginacao consultarPaginado(int pagina, Integer cidadeId) {
I'm not sure if I understand your question correctly, but if your query retrieves entities with toMany associations join-fetched, then pagination won't work as expected.
Indeed, suppose you have 4 A entities, each with 3 B entities, and suppose your query retrieves all the A entities with their Bs.
In that case, the SQL query will return 12 rows. If you use setMaxResults(7), it will retrieve (for example) three rows for A1 and its Bs, three rows for A2 and its Bs, and just 1 row for A3 and its first B.
And since you have used DISTINCT_ROOT_ENTITY, the criteria query will return only three entities: A1, A2, and A3 (which will have an incomplete set of Bs).