-->
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: Bug? Criteria returning same instance twice in list
PostPosted: Fri Feb 03, 2006 6:19 am 
Regular
Regular

Joined: Tue Jan 03, 2006 11:43 am
Posts: 51
Location: Sweden
When running the below code, I get multiple Containers with same ID.
Should this ever happen?
If I comment out the SetFetchMode row it works correctly (from my point-of-view at least).

Code:
            IList list = m_session.CreateCriteria(typeof(Container)).
                Add(Expression.Eq("ScorecardId", id)).                             
                SetFetchMode("Node.m_visibility", FetchMode.Eager).               
                List();                 


ScorecardId and Node are properties of Container.

/Carl


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 03, 2006 10:29 am 
Newbie

Joined: Fri Jan 20, 2006 12:47 pm
Posts: 16
Location: Ottawa, On
Hi Carl,

you need to add .SetResultTransformer(NHibernate.CriteriaUtil.DistinctRootEntity) to your Criteria query.

ICriteria crit = m_session.CreateCriteria(typeof(Container));
crit.Add(Expression.Eq("ScorecardId", id));
crit.SetFetchMode("Node.m_visibility", FetchMode.Eager);
crit.SetResultTransformer(NHibernate.CriteriaUtil.DistinctRootEntity);

IList list = crit.List();

Adding the result transformer is effectively the same as doing a "select distinct ... " sql or hql query. The difference with ICriteria is that instead of adding the distinct clause to the generated sql, the result transformer adds each object created from the underlying ado reader to a Hash and therefore any dups are discarded before the final collection is returned.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 03, 2006 12:34 pm 
Regular
Regular

Joined: Tue Jan 03, 2006 11:43 am
Posts: 51
Location: Sweden
It worked. Thanks a lot!


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 03, 2006 1:05 pm 
Newbie

Joined: Fri Jan 20, 2006 12:47 pm
Posts: 16
Location: Ottawa, On
no problem


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.