-->
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.  [ 4 posts ] 
Author Message
 Post subject: ICriteria not flattening results
PostPosted: Thu Oct 20, 2005 11:33 am 
Senior
Senior

Joined: Sat Sep 10, 2005 3:46 pm
Posts: 178
I have a mapping for a persistent object that specifies that one of its collections should be outer joined so that all of the data was queried at once.
Here is an excerpt form the mapping file:
Code:
<class name="HttpMenuItem" table="MenuItem" mutable="false" >
   <!--ID-->
   <id name="Id" type="System.Int32" column="MenuItemId" unsaved-value="0" access="field.camelcase-underscore">
         <generator class="identity" />
      </id>
      
   <!--PROPERTIES-->
   <property name="Name" column="Name" length="50" not-null="true" access="field.camelcase-underscore"/>
                        
   <!--COLLECTIONS-->
   <list name="NavigateUrls" table="MenuItemUrl"  lazy="false" access="field.camelcase-underscore" outer-join="true" batch-size="10">
         <cache usage="read-only" />
         <key column="MenuItemId"  />
         <index column="Sequence" />
         <element type="System.String" column="Url" not-null="true" length="255" unique="true"  />
      </list>            
</class>


When querying with the ICriteria interface, I was under the impression that NHibernate would flatten the resultset. This is not occuring. I am getting duplicates of the same object in my resultset depending on how many NavigatUrls each menu item has. As soon as I set outer-join="false" on the NavigateUrls collection, everything works as planned.

Is this a bug?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 20, 2005 3:39 pm 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
Try criteria.SetResultTransformer(CriteriaUtil.DistinctRootEntity);


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 20, 2005 7:53 pm 
Senior
Senior

Joined: Sat Sep 10, 2005 3:46 pm
Posts: 178
This worked fine Sergey. Thanks. But I though that the was the default with ICriteria. Is this not the case?

Whats the best way to flatten the results aof n HQL query. Hibernate in action says to do something like this:

Code:
distinctResult = new HashSet(resultList);


but .net does not have a HashSet. Would the Iesi HashedSet work?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 21, 2005 7:37 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
Criteria is translated into SQL and you just get the result set of the SQL query, transformed into objects. So if a query gives you duplicate rows, then you get duplicate objects.

Yes, Iesi set would work with HQL.


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