-->
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: filter collection based on business method
PostPosted: Sat Mar 06, 2004 9:13 pm 
Newbie

Joined: Mon Feb 16, 2004 11:39 pm
Posts: 2
Is there a way to filter a collection of the type "parent.children" based on a business method on this child class?

I have the child class like this:
Code:
public class Child {

  // field declarations...

  public boolean businessMethod(String parameter) {
   // implementation...
  }

}


I want to filter from parent all the children which do not return true on businessMethod()

How do I do this?

Ps: I have tried to iterate over children collection and do a remove() on iteration element, but it removed the relationship of the child object, of course.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Mar 07, 2004 5:35 pm 
Proxool Developer
Proxool Developer

Joined: Tue Aug 26, 2003 10:42 am
Posts: 373
Location: Belgium
Do something like this:

Code:
public class Parent {
  private List children;

  public List getChildren() {
    List res = new LinkedLIst();
    for(Iterator it=children.iterator(); it.hasNext(); ) {
      Child child = (Child) it.next();
      if( businessMethod(child) )
         res.add(child);
    }
  }

  protected boolean businessMethd(Child child) {
     ...
  }
}


Now Hibernate can't use the getChildren() method anymore to persist the collection. Two solutions:
1/ either declare another method Hibernate will use;
2/ either map the collection with access="field" (so Hibernate will bypass the getter and access the member variable directly).

And you have what you want ;-)


Top
 Profile  
 
 Post subject:
PostPosted: Sun Mar 07, 2004 10:15 pm 
Newbie

Joined: Mon Feb 16, 2004 11:39 pm
Posts: 2
Thanks brenuart,

It seems that hibernate do not support this kind of filter.
So, it will be a good solution :)


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.