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.  [ 2 posts ] 
Author Message
 Post subject: The DAO pattern and aggregate functions
PostPosted: Sun Aug 17, 2008 9:53 am 
Newbie

Joined: Sun Aug 17, 2008 9:43 am
Posts: 2
I'm using the DAO pattern in a Hibernate project, so I have a Hibernate DAO that implements the standard DAO methods: new, fetchAll, fetch(ID), save(model), update(model), delete(model).

I have a model called User that's linked to many Account models. I'd like to do is keep any HQL in the DAO's themselves, but I also would like to calculate the total balance of a User's attached accounts.

This would be the ideal pattern:
Code:
User user = userDAO.fetch( ... );
user.getTotalBalance() // sums the balances in the user's accounts, preferably completely in the database


Is there anything in Hibernate mappings that I can use to map to a calculated value, e.g. (SELECT SUM(a.Balance) FROM Account a WHERE a.UserID = User.ID)? I suppose my other alternative is to create a getTotalBalance( User user ) in UserDAO, but that doesn't seem like the cleanest solution.[/img][/list][/code]


Top
 Profile  
 
 Post subject: Re: The DAO pattern and aggregate functions
PostPosted: Sat Sep 12, 2009 2:50 pm 
Newbie

Joined: Sat Sep 12, 2009 2:10 pm
Posts: 2
I have been searching about the same problems for days. I have found about filters with join, subselects and projections are needed to do what you have wanted, IMHO. Could you be able to found a clean way?


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