-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Criteria API : pagination biaised with outer join collection
PostPosted: Mon Sep 07, 2009 10:10 am 
Newbie

Joined: Mon Dec 01, 2003 12:41 pm
Posts: 12
Location: Aix en Provence, France
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.


Top
 Profile  
 
 Post subject: Re: Criteria API : pagination biaised with outer join collection
PostPosted: Tue Feb 09, 2010 11:20 am 
Newbie

Joined: Fri Feb 05, 2010 11:00 am
Posts: 3
Same here. Any solution?


Top
 Profile  
 
 Post subject: Re: Criteria API : pagination biaised with outer join collection
PostPosted: Sun Feb 14, 2010 12:03 pm 
Newbie

Joined: Mon Dec 01, 2003 12:41 pm
Posts: 12
Location: Aix en Provence, France
nope
This "features" / bugs are not recent ...
It could be considered a feature for the HQL API
But this is certainy a bug for the Criteria API
I'll try the new beta JPA2 to check ...

_________________
Gauthier P.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.