-->
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: Put functionality in domain objects or DAO?
PostPosted: Sun Mar 26, 2006 1:38 pm 
Beginner
Beginner

Joined: Mon Mar 20, 2006 7:59 am
Posts: 30
Hello,

I am not sure how to design what I want to do. I have some kind of business logic and I am not sure where to put this logic. For instance I have a Customer class and an Order class.

Now I want to get the number of a customer's orders. I could add a "GetOrderCount()" method in my UserDAO to get this number. Or I could add a property "OrderCount" to the Customer class that gives me that number. But that would mean that the Customer class must be able to query nhibernate for this number.

In this particularly case I would add the method to the UserDAO - but there are other cases where I would need this information directly in the Customer class. What do you do in such a case? Implement another abstract dataaccess layer or use nhibernate in the class? Of course I could use the customer's properties to navigate to the information I was searching for but that is very inefficient.

Thanks in advance for good suggestions :)

Regards,
Dominik


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 27, 2006 12:05 am 
Newbie

Joined: Wed Oct 12, 2005 10:28 pm
Posts: 10
"Now I want to get the number of a customer's orders. I could add a "GetOrderCount()" method in my UserDAO to get this number. Or I could add a property "OrderCount" to the Customer class that gives me that number. But that would mean that the Customer class must be able to query nhibernate for this number. "

Actually your Customer class don't have to query database using DAO..if you do like this it will coupling your domain object to DAO.. what you can do, let's client call DAO and return Domain Object to client.. and you can have GetOrderCount() in your Customer class which will return ordercount value.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 27, 2006 2:51 am 
Beginner
Beginner

Joined: Mon Mar 20, 2006 7:59 am
Posts: 30
ryzam wrote:
"let's client call DAO and return Domain Object to client.. and you can have GetOrderCount() in your Customer class which will return ordercount value.


But that is the point. How does the Customer class know the order count. Well, the Customer has of course a property Orders which is a list with the orders. But it gets loaded lazily and if a customer has a lot of orders I don't want to load all of them due to performance issues.

It maybe for example that I need a list of all the customers and there orders count. It would be totally inefficient to NOT query this via HQL. Or are these things just not possible?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 27, 2006 3:29 am 
Newbie

Joined: Wed Oct 12, 2005 10:28 pm
Posts: 10
sir-archimedes wrote:
ryzam wrote:
"let's client call DAO and return Domain Object to client.. and you can have GetOrderCount() in your Customer class which will return ordercount value.


But that is the point. How does the Customer class know the order count. Well, the Customer has of course a property Orders which is a list with the orders. But it gets loaded lazily and if a customer has a lot of orders I don't want to load all of them due to performance issues.

It maybe for example that I need a list of all the customers and there orders count. It would be totally inefficient to NOT query this via HQL. Or are these things just not possible?


Ok...i think this is more on performance issue.. actually order count is not involve in any business logic.. then i think it's acceptable to query database return the count value.. where you can supply hql to get order count.


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.