-->
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: Best way to filter collection
PostPosted: Tue Dec 29, 2009 6:40 am 
Newbie

Joined: Thu Aug 27, 2009 5:08 am
Posts: 3
Hi
I have the following scenario.

I have a list of Customers, each customer has a list of Orders. I want to get all the customers but i only want to load the orders for the customers within a specific date range. Whats the best way to solve this with ICriteria? Should I use CreateFilter on the session insted?

Is it in some way possible to create this filtering already in the ICriteria?

/Edit
I dont want to use filter, because it will produce to many selects. Is it possible with ICriteria thou?

Regards


Top
 Profile  
 
 Post subject: Re: Best way to filter collection
PostPosted: Fri Jan 01, 2010 5:38 am 
Newbie

Joined: Tue Dec 22, 2009 9:39 am
Posts: 3
Are you sure you want to filter the Collection itself, rather than an iterator? see org.apache.commons.collections.iterators.FilterIterator

_________________
g-string
replica watches


Top
 Profile  
 
 Post subject: Re: Best way to filter collection
PostPosted: Mon Jan 11, 2010 1:20 pm 
Newbie

Joined: Sat Jan 09, 2010 3:23 pm
Posts: 5
Code:
session.CreateCriteria(typeof(Order))
                        .Add(Expression.Between("Date", date_min, date_max))
                        .List()


Cheers,
Andre


Top
 Profile  
 
 Post subject: Re: Best way to filter collection
PostPosted: Fri Feb 05, 2010 2:19 pm 
Newbie

Joined: Sat Dec 26, 2009 7:05 am
Posts: 8
you can do this with one db acces :

create a criteria on customers : custCriteria
custCriteria.CreateCriteria("Orders","Order", NHibernate.SqlCommand.JoinType.LeftOuterJoin)
now add a criterion as the user above me showed, but with the alias Order
this will fetch all employees (because it is a left out join) and only the wanted orders
or you could do as he said with 2 db access. the more efficient strategy depends mainly on how big is the customer record (with a join, the same customer record returns few times - one for each of its orders)

also, if you use a join, use result transformer to return any root entity only once


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.