Gentlemen, I'm trying to model a rather unusual relationship, and AFAIK there's no way to achieve that in Hibernate, but wanted to here others thoughts before I give up.
At the guts, the model is plain vanilla. Parent entity A that contains a collection of entity B. Both entities are very simple, PK, and numeric value.
class A {
String id,
int value
List<B> children
}
class B {
String id,
A parent;
int value;
}
What's interesting about this relationship is that certain instances of A can contain very large number of Bs (in thousands). That turns out to be a performance hit when operating on those instances. What's interesting about this case - A doesn't actually care about individual children - but only about the aggregate sum of 'value' field on all children.
Is there a way to map B to A so that it's loaded in a single aggregate SQL operation, as opposed to individual rows. Obviously, I can always create a VIEW on top of table B, but I'd prefer a software approach.
|