It's not a secret anymore!
The moose likes OO, Patterns, UML and Refactoring and the fly likes dao pattern Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Engineering » OO, Patterns, UML and Refactoring
Bookmark "dao pattern" Watch "dao pattern" New topic

dao pattern

narender sunkam
Ranch Hand

Joined: May 01, 2004
Posts: 30
Hi ranchers,
I am very much confused with dao pattern
can any one explain me dao pattern with a simple example
I want some thing like discussion on this topic.

narender kumar
Maryam Nouhnejad
Ranch Hand

Joined: Oct 04, 2006
Posts: 39
It would be nice if you could write how much have you studied so far and what have made you confused in this subject...Anyway...

A typical DAO (Data Access Object) implementation has the following components:

�A DAO factory class
�A DAO interface
�A concrete class that implements the DAO interface
�Data transfer objects (sometimes called value objects)

You have to also know these assumptions behind the DAO implementation:

1 . All database access in the system is made through a DAO to achieve encapsulation.

2 . Each DAO instance is responsible for one primary domain object or entity. If a domain object has an independent lifecycle, it should

have its own DAO.

3 . The DAO is responsible for creations, reads (by primary key), updates, and deletions -- that is, CRUD -- on the domain object.

4 . The DAO may allow queries based on criteria other than the primary key. I refer to these as finder methods or finders. The return

value of a finder is normally a collection of the domain object for which the DAO is responsible.

5 . The DAO is not responsible for handling transactions, sessions, or connections. These are handled outside the DAO to achieve


So, which part of that do you intend to discuss with the others??...

Paul Sturrock

Joined: Apr 14, 2004
Posts: 10336

Moving to our design forum...

JavaRanch FAQ HowToAskQuestionsOnJavaRanch
narender sunkam
Ranch Hand

Joined: May 01, 2004
Posts: 30
Thanks Maryam for responding
I have an doubt like how to implement dao pattern
can briefly explain me taking a small example
Ilja Preuss

Joined: Jul 11, 2001
Posts: 14112
Google for "dao example". Study the examples and come back with more specific questions.

As an aside, I'd say that per default a DAO should return fully fledged domain objects, not DTOs. See

The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Peer Reynders

Joined: Aug 19, 2005
Posts: 2933
Blueprints: DAO Pattern
Core J2EE Patterns: Data Access Object

Note that there are other database access patterns besides the J2EE DAO
Active Record
Table Data Gateway, Row Data Gateway, Data Mapper
I agree. Here's the link:
subject: dao pattern
It's not a secret anymore!