| Register | FAQ | Calendar | Search | Today's Posts | Mark Forums Read |
|
#1
| |||
| |||
| Hi, quick question about accessing the persistence layer, in particular using DAO vs. using ORM. Let's say I have a Customer class which has a 1:N relationship to his purchases, so for ORM, I would do something like this: class Customer { int id; List<Purchase> purchases; // also include all the usual, firsname, lastname, etc int getId(); setId(); List getPurchases(); setPurchases(); } class Purchase { int id; // purchaseName, date, etc... setId(); int getId(); } So to get the purchases for a particular customer, using ORM, I would so something like: Customer c = ORMManager.load(c, customerid); then I would do List p = c.getPurchases(); to get the purchases. Now, for the DAO pattern, I would do this instead: List p = PurchasesDAO.getPurchasesByCustomer(customerid); so then I would not even need a reference to the list of purchases in the Customer class... SO, my question is, it seems to me that the persistence layer should not dictate the modelling of the business objects, yet this seems to contradict that. What would you suggest? If using the DAO pattern it seems like all business objects would have no references to any other business objects. -Tom |
![]() |
| Thread Tools | |
| Display Modes | |
In an effort to better serve ads to our visitors, cookies are used on objectmix.com. For more information, check out our Privacy Policy.