DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Last call! Secure your stack and shape the future! Help dev teams across the globe navigate their software supply chain security challenges.

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workloads.

Releasing software shouldn't be stressful or risky. Learn how to leverage progressive delivery techniques to ensure safer deployments.

Avoid machine learning mistakes and boost model performance! Discover key ML patterns, anti-patterns, data strategies, and more.

Related

  • Workarounds for Oracle Restrictions on the Size of Expression Lists
  • Tired of Messy Code? Master the Art of Writing Clean Codebases
  • The Journey of Becoming a Blockchain Developer
  • JSON-Based Serialized LOB Pattern

Trending

  • Analyzing “java.lang.OutOfMemoryError: Failed to create a thread” Error
  • Enhancing Security With ZTNA in Hybrid and Multi-Cloud Deployments
  • Understanding and Mitigating IP Spoofing Attacks
  • Beyond Microservices: The Emerging Post-Monolith Architecture for 2025
  1. DZone
  2. Software Design and Architecture
  3. Security
  4. One Big DAO, or One DAO Per Table/Object?

One Big DAO, or One DAO Per Table/Object?

By 
Jakob Jenkov user avatar
Jakob Jenkov
·
Jul. 30, 09 · Tutorial
Likes (3)
Comment
Save
Tweet
Share
46.6K Views

Join the DZone community and get the full member experience.

Join For Free

For a long time I have been doing DAO's in my applications.I have usually used the model of having one DAO per type persisted, or per database table. You know, a PersonDao, a CarDao, a BlablaDao etc.

Today, as I was writing an application in which I am too lazy to use a DAO layer (because most
of the persistence operations are 1-liners), I was thinking: Should I add that DAO layer, or should
I not care? Well, of course I should add the DAO layer, so SQL statements etc. can be reused,
and modified in a central place, if the database schema changes. Shame on me for being lazy.

But here is my question to you all:

Do you also use one DAO per type persisted?
Or, do you create one BIG DAO which contains all DAO logic?

I am asking, because I feel tempted to go with just one BIG DAO though I have no experiences
with that. Like I said, I usually use one DAO per type persisted. But a BIIIG DAO seems compelling to me...
Here are the immediate benefits I can see:

  1. It definately makes it easier to find all DAO methods in a project.
  2. It makes it very easy to share connections and transactions between different DAO calls.
  3. You don't get confused about whether readCarsForPerson() belongs in the CarDao or PersonDao
    (I would probably say CarDao since it returns Car's).


By using one big DAO the DAO becomes an abstraction of the total database / datastore, rather than an abstraction of each table / type etc.

What is your opinion on this? One big DAO, or one per type? Does anyone have any experiences?

Decentralized autonomous organization

Opinions expressed by DZone contributors are their own.

Related

  • Workarounds for Oracle Restrictions on the Size of Expression Lists
  • Tired of Messy Code? Master the Art of Writing Clean Codebases
  • The Journey of Becoming a Blockchain Developer
  • JSON-Based Serialized LOB Pattern

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends: