-->
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: Query object with filtered collections
PostPosted: Tue Jul 29, 2008 9:16 pm 
Newbie

Joined: Sun Jun 29, 2008 3:14 pm
Posts: 6
Hi.

I want to query an object that has a collection and have that collection be fetched with the constraints in the query.

I mean:
I have a Grantee object that has a Grant collection, Grant has among others a Year property. I want to fetch all Grantees with Grant.Year > xxxx

I have this criteria query:
Code:
ICriteria granteeCrit = s.CreateCriteria(typeof(Grantee));
ICriteria grantCrit = granteeCrit.CreateCriteria("Grants");

grantCrit.Add(Expression.Ge("Year", year));
granteeCrit
   .Add(Expression.Eq("Active", true))
   .AddOrder(Order.Asc("LastName"))
   .AddOrder(Order.Asc("FirstName"));

IList<Grantee> a = granteeCrit.List<Grantee>();


The thing is, when I do a foreach on Grantee.Grants the collection has all of the elements, not just the ones where Year > xxxx

Is there any way to constraint the collection on the query?

Thank you very much
Alex


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 30, 2008 5:59 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
Have a look at section 12.4, especially the end:

http://www.hibernate.org/hib_docs/nhibernate/1.2/reference/en/html/querycriteria.html#querycriteria-associations

_________________
--Wolfgang


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 30, 2008 10:18 am 
Newbie

Joined: Sun Jun 29, 2008 3:14 pm
Posts: 6
Thank you very much Wolli.
I can't believe I missed that part, I've searched a lot through the doc before even thinking of posting a quesetion, but well :/

Thanks again.


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.