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: How to filter in-memory collections?
PostPosted: Mon Nov 19, 2007 10:52 am 
Beginner
Beginner

Joined: Mon May 14, 2007 2:50 am
Posts: 22
Just pondering what Hibernate/NHibernate users think of filtering an in-memory collection?

Say, I have already loaded into memory an object Cat, and cat has a lot of kittens, and they are already loaded into memory.

What i want to do next is to just display in the grid only those kittens, which match some specific criteria, like, kitten name is like "joe".

How would you do that?

I wonder, is there a way to do that, hopefully having the same ICriteria API. I looked at documentation and see that CreateFilter is only for HQL, that's too bad


Top
 Profile  
 
 Post subject: Re: How to filter in-memory collections?
PostPosted: Mon Nov 19, 2007 11:06 am 
Beginner
Beginner

Joined: Mon May 14, 2007 2:50 am
Posts: 22
DarkCloud wrote:
Just pondering what Hibernate/NHibernate users think of filtering an in-memory collection?


Filtering in memory is actually not the most brilliant idea. It sounds ok at first glance, but on having inspected it more thoroughly, i got that filtering in memory would produce more headache than pleasure.

I'm still though wondering what is the preffered way to filter association collections with ICriteria like API?

one workaround instead of using session.CreateFilter()
Code:
kittens = s.Filter( cat.kittens, "name like 'joe');

would be to use the same ICriteria statements, and add aditional filtering to filter cat
Code:
criteria.Add(Expression.Like("Name", "Joe"));
crtieria.Add(Expression.Equals("KittenMother", mother));


What do you think about this hack (it does not look like the right thing to do...)?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 19, 2007 12:13 pm 
Senior
Senior

Joined: Thu Feb 09, 2006 1:30 pm
Posts: 172
I assume you are talking about non-trivial filtering of the collection. The best bet to me at this point would be upgrade to Visual Studio 2008 and Linq when it is available (if you can). Linq works well to filter in-memory objects.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 20, 2007 3:19 am 
Beginner
Beginner

Joined: Mon May 14, 2007 2:50 am
Posts: 22
jchapman wrote:
The best bet to me at this point would be upgrade to Visual Studio 2008 and Linq when it is available (if you can). Linq works well to filter in-memory objects.


That's an idea, although i will not test it on our mission critical project :D

By the way, SharpDevelop3 works with .Net 3.5, so you can grab and test it, although at the current moment is very very unstable
http://community.sharpdevelop.net/blogs/laputa/archive/2007/11/19/net-framework-3-5-release.aspx


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.