-->
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.  [ 4 posts ] 
Author Message
 Post subject: Value object or entities
PostPosted: Mon Sep 10, 2007 10:45 pm 
Newbie

Joined: Wed Jun 21, 2006 2:25 pm
Posts: 15
hi all,

Consider an entity model which has 2 entities ACCOUNT and TRANSACTION. ACCOUNT can have multiple TRANSACTIONs. Further each TRANSACTION is associated with a amount attribute.

On a web front end I would like to show the ACCOUNT and the sum of amount of associated TRANSACTIONs. How do you propose this be should be efficiently implemented in hibernate. One of the prime criteria for efficiency would be the number of queries the application fires for any business operation.

Iny my opinion there are 2 options
1. Create a business method on the ACCOUNT entity which declares a method BigDecimal::getAccountTotal(). This looks into the collection of TRANSACTIONs and sums up the amount. The trouble with this approach is that it can fire one query for every ACCOUNT.

2. In the second approach define a method on the dao List<AccountBalanceVO>::getAllAccountTotals(). The dao can first retrieve all the account entities and then fire an additional query to retrieve all the account ids and the sum of account. Finally the dao can combine both the results into a value object and send it over to the presentation tier. In this approach only 2 queries are fired. While I prefer this approach, it clearly moves away from some the entity notion.

Questions to the group
1. which of the alternatives would you prefer and why ?
2. Are there any additional alternatives ?

Thanks
anand raman


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 12, 2007 12:34 am 
Newbie

Joined: Wed Jun 21, 2006 2:25 pm
Posts: 15
any thoughts ?. Apologies for asking the question again

anand


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 12, 2007 2:57 am 
Newbie

Joined: Wed Sep 05, 2007 6:34 pm
Posts: 13
Ooh, very interesting question.

I would prefer both implementations--the 2nd for the survey from the presentation and the 1st for single-account display and for general sensibility. Relying on just the 1st wouldn't be scalable and leaves a panging "what-if" around.

I'm not sure if the following would work, but how about something having to do with formulas or derived/computed properties?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 12, 2007 4:29 am 
Newbie

Joined: Wed Jun 21, 2006 2:25 pm
Posts: 15
hi "confused one", thanks for your suggestions. It would be interestign to see if we can do it using formulas or derived properties. I guess the answer is "no". But I will wait for someone more knowledgable who can help us out.

anand


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.