-->
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: Restrictions on Collection
PostPosted: Fri Jul 08, 2005 3:43 pm 
Newbie

Joined: Thu Jul 21, 2005 3:02 am
Posts: 11
Sorry for my ignorance I'm quite new to NH. I have read "Hibernate in action" but is still missing something.

The situation is:

ClassA contains a list of ClassB. The IList of ClassB is lazy loaded. Is it possible to make restrictions on the IList of ClassB when accessed through ClassA.ClassBCollection? For every ClassA there could be 1000 ClassB's but I always want ClassB where ClassB.Year=2005.

Can this be done???

Regards Morten


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jul 09, 2005 1:45 pm 
Expert
Expert

Joined: Fri May 13, 2005 5:56 pm
Posts: 308
Location: Santa Barbara, California, USA
You can use a "where" attribute and place standard SQL tags. I've never used it so you might have to play with it for a while but you will want to do something like this in the ClassA mapping file:

Code:
<bag  name="ClassBCollection"
         table="ClassBTable"
         lazy="true"
         where="Year = 2005" />


The where is SQL, so like I said, you might have to play with it to match the definition of the table column.

-devon


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jul 10, 2005 10:37 am 
Contributor
Contributor

Joined: Thu May 12, 2005 9:45 am
Posts: 593
Location: nhibernate.org
You can also load ClassB entities (with a HQL like "from ClassB b where b.Year = 2005 and b.ClassA.Id = XXX")
But you will not have the collection ClassA.ClassBCollection initialized...

_________________
Pierre Henri Kuaté.
Get NHibernate in Action Now!


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jul 10, 2005 12:56 pm 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
Or use Session.CreateFilter (someObj.ListOfClassBs, "some HQL condition")


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.