When I have a Criteria request from a root element (Company for example) with a fetchMode JOIN and an Alias LEFT_OUTER_JOIN to a collection (Employees for example), I don't manage to get distinct Companies paginated (with MaxResults and firstElement).
criteria = sessionFactory.getCurrentSession().createCriteria(Company.class);
criteria.createAlias("employees", "employees", JoinType.LEFT_OUTER_JOIN);
criteria.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY);
criteria.setFetchMode("employees", FetchMode.JOIN);
criteria.setFirstResult((pageNb - 1) * nbPerPage);
criteria.setMaxResults(nbPerPage);
If I ask for the firsts 20 companies, I only have 3 because the first of the results has 18 employees.
I would like to have the firsts 20 as asked but with the employees loaded to optimised the lazy loading.