fetch join collection break firstResult/MaxResult in hibernate
December 18, 2014
Posted by on
If a fetch join is used along with order by, hibernate will load all records into memory to do the sorting. It will ignore the firstResult/MaxResult which mean no real database pagination.
em.createQuery("SELECT a FROM TicketTracker tt
LEFT JOIN tt.ticket a
LEFT JOIN FETCH a.conversation tc
WHERE a.status!=400 GROUP BY tt.ticket ORDER BY a.dueDate", TicketActivity.class)
In this example, even we didn’t order records by the join entity, the join fetch still break the setFirstResult/SetMaxResult . I have to write a seperate query to fetch the conversations records.