-->
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: GetAll query
PostPosted: Wed Oct 18, 2006 8:52 am 
Newbie

Joined: Wed Oct 18, 2006 8:47 am
Posts: 3
Hi,

I'm trying return all data from MS SQL 2000 table. I'm using below code:

public List<T> GetAll() {
return GetByCriteria();
}

public List<T> GetByCriteria(params ICriterion[] criterion) {
ICriteria criteria = session.CreateCriteria(persitentType);

foreach (ICriterion criterium in criterion) {
criteria.Add(criterium);
}

return ConvertToGenericList(criteria.List());
}

Everthing works ok but in query profiler I see that NHibernate makes query for each entity, so if table contains 2000 records NHibernate run 2000 query.
Is is possible to optimalize this search proces.

Thanks.


Top
 Profile  
 
 Post subject: Re: GetAll query
PostPosted: Wed Oct 18, 2006 4:00 pm 
Beginner
Beginner

Joined: Wed Aug 03, 2005 8:06 am
Posts: 40
Location: Netherlands
Could it be that NHibernate is querying additional data after having executed the first query for the criteria.List(), e.g. to populate a non-lazy many-to-one relationship? Could you give an example of your mapping and generated SQL?


Top
 Profile  
 
 Post subject: Re: GetAll query
PostPosted: Thu Oct 19, 2006 6:29 am 
Newbie

Joined: Wed Oct 18, 2006 8:47 am
Posts: 3
GeAr wrote:
Could it be that NHibernate is querying additional data after having executed the first query for the criteria.List(), e.g. to populate a non-lazy many-to-one relationship? Could you give an example of your mapping and generated SQL?


Yes it was non-lazy many-to one relationship issue. I modified my mapping to
<bag name="FWXIndLocations" inverse="true" fetch="join">
<key column="IndividualID" />
<one-to-many class="FSI.Core.Domain.FWXIndLocation, FSI.Core" />
</bag>

I added fetch="join".

Thanks.


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.