What is the most efficient way to deal with transitive one-to-many mappings? For example, one A has many Bs, and one B has many Cs, and I want a set of all Cs associated with a certain A.
So conceptually I want:
Code:
Set s = instanceOfA.getBs().getCs();
My most recent attempt looked like this:
Code:
Iterator it = instanceOfA.getBs().iterator();
while (it.hasNext()){
if (s == null){
s = ((B) it.next()).getCs();
}
else{
s.addAll(((B) it.next()).getCs());
}
}
It seems like there must be a better way to do it than adding all those sets together.
The other way that came to mind to do it was to do a join in HQL, but I think that is to be avoided:
Code:
String queryString = "select c from C as c join c.B as b join b.A as a where a.property = 'Value'";
Iterator it = sess.iterate(queryString);