DAO
Closer to storage concerns, SQL queries, ORM operations, and data retrieval mechanics.
Teams often use DAO and Repository interchangeably, but they are not quite the same idea. DAO is usually a persistence-oriented access abstraction. Repository is more domain-facing and is often framed around aggregate roots and domain concepts. This page clarifies the difference.
The distinction matters most when teams are mixing enterprise layering with DDD. If a class is really a data-access wrapper, calling it a repository can make the domain sound richer than it is. If a class is meant to represent aggregate access, calling it a DAO can undersell the model boundary it is supposed to support.
A DAO normally speaks in persistence or query terms. A Repository normally speaks in domain terms and is usually aligned with aggregate boundaries. In simple applications, the distinction may be light. In DDD-style applications, the difference becomes more meaningful because repository abstractions communicate model ownership and invariants more clearly.
Closer to storage concerns, SQL queries, ORM operations, and data retrieval mechanics.
Closer to domain language and aggregate access semantics.
Many real codebases mix them, so naming clarity matters more than dogma.
| Aspect | DAO | Repository |
|---|---|---|
| Primary lens | Persistence access | Domain model access |
| Typical vocabulary | Rows, queries, records, persistence operations | Aggregates, domain identities, business retrieval |
| Best fit | Data access layers and integration-centric persistence work | DDD-style aggregate access and domain-facing persistence boundary |
| Risk | Too storage-shaped for rich domain language | Repository name used for thin CRUD wrappers with no domain meaning |
package org.javaomnibus.reference;
public interface OrderDao {
OrderRecord findRecordById(String orderId);
}
public interface OrderRepository {
Order findById(OrderId orderId);
}