Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

modeling--DAO vs ORM

843830Jan 21 2006 — edited Jan 26 2006
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.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 23 2006
Added on Jan 21 2006
2 comments
458 views