-->
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: Any thoughts how to model the following relationship...
PostPosted: Sat Mar 21, 2009 11:08 pm 
Newbie

Joined: Mon Nov 26, 2007 4:10 pm
Posts: 6
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.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Mar 22, 2009 10:34 am 
Regular
Regular

Joined: Mon Nov 24, 2003 6:36 pm
Posts: 105
Some options:
1. using a "formula" field on your parent mapping
2. map a separate object to a db view (won't be persistent, but would be loadable)


Top
 Profile  
 
 Post subject:
PostPosted: Sun Mar 22, 2009 4:20 pm 
Newbie

Joined: Mon Nov 26, 2007 4:10 pm
Posts: 6
@Formula worked beautifully. Until now, I didn't realize that I could use subselect within a formula.


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.