-->
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.  [ 2 posts ] 
Author Message
 Post subject: Problem with DISTINCT_ROOT_ENTITY and Criteria.setMaxResults
PostPosted: Fri Nov 07, 2008 5:45 am 
Newbie

Joined: Fri Oct 03, 2008 8:23 am
Posts: 4
Hello

Thank you, the Hibernate community, for the anser to my last question.

Now I discover another problem but I did not find answer for this case on the internet:

I have an entity class, say 'MyEntity', with is related to several entities (it is aggregated by class 'Groupe', the class 'History' relates two MyEntity instances, ....).

What i would like to do is a sorted list ('paginated' means getting result from N to N+100) of MyClass instances, with the all related instances loaded (not lazy).

First, I try this criteria:
session.createCriteria(MyEntity.class).
setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY).
setMaxResult(100).

It works OK when my database size is small (less than 100)

When the database size is bigger than 100,
the result list is imcomplete !
If I set the max result 100, I get 2 results,
if I change max result to 1000, I get 10 results, .......

It seems that Hibernate applies
the size limitation to the duplicated list BEFORE
filterring the duplicated elements.
That is why I get less than 100 results.

Could you please help me ?
Thank you !

Hibernate version:
3.2.6


Mapping documents:

Code between sessionFactory.openSession() and session.close():

Criteria criteria = session.createCriteria(MyEntity.class);
criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
criteria.setMaxResults(100);






Full stack trace of any exception that occurs:

Name and version of the database you are using:
MySQL 5



The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 07, 2008 7:41 pm 
Expert
Expert

Joined: Mon Nov 26, 2007 2:29 pm
Posts: 443
Well, as you realized already, the pagination feature relies on the record count of the un-transformed resultset, so you shouldn't use it in combination with transformations.

Thinking about it, it makes sense: if transform a resultset into a tree-like structure, is because you plan to read it using Java code, not a simple "rectangular" select.

_________________
Gonzalo Díaz


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.