my dog learned polymorphism
The moose likes OO, Patterns, UML and Refactoring and the fly likes One big DAO or a DAO per entity? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » OO, Patterns, UML and Refactoring
Bookmark "One big DAO or a DAO per entity?" Watch "One big DAO or a DAO per entity?" New topic

One big DAO or a DAO per entity?

Otis Onesh

Joined: Jul 04, 2013
Posts: 6
I have seen some discussions on the internet on this subject - most were 2-3 years old - and the results are inconclusive. Are there any suggestions on how to do it nowadays with jpa and all?
Jeanne Boyarsky
author & internet detective

Joined: May 26, 2003
Posts: 33102

Welcome to CodeRanch!

I prefer to keep to one DAO per entity. Sometimes when the entities are closely related, I don't though. Or if I have reporting type queries that span a lot of tables.

In other words "it depends" which is why you aren't finding anything conclusive.

[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
Sujeeth Pakala
Ranch Hand

Joined: Mar 24, 2009
Posts: 104
Hello Otis,

To keep it simple : Use one DAO per entity.
To take advantage of Object oriented programming (ad to have fun !) : Generalise the CRUD ooperations using Abstraction. This way, your DAO class should be able to perform persistent opertaions on any type of entity

Good Luck !

Regards, Sujeeth Pakala
SCJP, SCWCD, SCBCD, ICAD, XML Master Basic, Certified SOA Professional
I agree. Here's the link:
subject: One big DAO or a DAO per entity?
It's not a secret anymore!