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 ;-)