hello,
When using Criteria with a join on a one-to-many association, paginiation does not work: ie setFirstResult() and setMaxResult() seem to work on the scalar product ans not on distinct entity counting. Ans setResultTransformer() does not help a bit ....
List<Film> list = (List<Film>) getSession().createCriteria(Film.class, "f").setResultTransformer( Criteria.DISTINCT_ROOT_ENTITY).setFirstResult(0).setMaxResults(10).createCriteria("inventories", "i", JoinFragment.LEFT_OUTER_JOIN).add(Restrictions.eq("i.store.id", new Long(1))).addOrder( Order.asc("f.id")).list();
With that query the List<Film> list should contains 10 Film. In fact the List<Film> list contains only 3 Films since Inventories for those film exceed already 10 ....
Is there a Solution in Hibernate 332 for this kind of problem ? need to wait for 3.5 and JPA 2 ?
NOte : in HQL , though fetching is not "clean" (the fetched xx-to-many collection are filtered by the where clause) the counting, and full pagination is correct. And one could always not use "fetch" and use a "subselect" to fill the collections afterward. Exemple of the same query in HQL : List<Film> list = (List<Film>) getSession().createQuery( "select f from Film as f left join fetch f.inventories as i where i.store.id = :id order by f.id") .setLong("id", 1L).setMaxResults(4).list(); In this case the inventories collection only contains Inventory Objects which relate to Store with id=1 And the pagination works fine !
How come pagination works for HQL and not Criterias ?
Have I done something wrong ?
_________________ Gauthier P.
|