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
|