-->
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: Distinct root is not distinct
PostPosted: Wed Sep 08, 2010 10:37 am 
Newbie

Joined: Mon Mar 15, 2010 9:11 am
Posts: 2
Hi there,

I'm having issues with getting proper query results using DISTINCT_ROOT_ENTITY. My query is as following:

detachedCriteria.add(Restrictions.in(idField, ids));
detachedCriteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
List objects = getHibernateTemplate().findByCriteria(detachedCriteria);

Reason for using the Restrictions.in construction is that I want to be able to limit the number of root objects. The query above is part of a larger retrieve() function.

The issue here is that the objects that are retrieved contain Lists of other referenced objects. The count of these referenced objects is not correct.

Inspecting the query shows me that an left outer join is used to gather that data. When executing the query directly in Oracle I receive 42 rows. When Hibernate has executed the query the list with referenced objects contains 42 objects as well. The strange thing here is that all of these objects have the same object reference, so its the same data. Which is correct, because there only exists one definition of those in the database.

I suspect that either the join type that is used is not correct; or that the DISTINCT_ROOT_ENTITY does not properly merge the rows into objects. This last one sounds the most plausible, since all objects in the list actually have the same object reference - and thus are the same.

I use Hibernate v3.3.2 within Equinox OSGi with Spring.

Any ideas or pointers? Thanks!


Top
 Profile  
 
 Post subject: Re: Distinct root is not distinct
PostPosted: Fri Jan 07, 2011 1:50 am 
Newbie

Joined: Thu Jan 06, 2011 3:23 pm
Posts: 3
What do you mean to imply by "detatchedCriteria"? If you are using a StatelessSession, then in my experience (Hibernate 3.6.0.Final) DISTINCT_ROOT_ENTITY does not work. Works fine with a regular Session however!


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.