This week's book giveaway is in the Agile forum.
We're giving away four copies of The Software Craftsman and have Sandro Mancuso on-line!
See this thread for details.
The moose likes Object Relational Mapping and the fly likes Do we need DAO layer Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of The Software Craftsman this week in the Agile forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Do we need DAO layer" Watch "Do we need DAO layer" New topic

Do we need DAO layer

Charu Sama

Joined: Aug 03, 2006
Posts: 12
Do we really need DAO layer if working with Hibernate, JPA or any other mapping framework. I had long discussion on this topic .....

Some says yes, but I donot know why??? just for or EntityManager.persist(), ?

Is this not a good design decision to omit DAO layer and let the Frameork do their jobs like generating SQL behind the secene, resource management.
Jimmy Clark
Ranch Hand

Joined: Apr 16, 2008
Posts: 2187
A well-designed DAO layer will enable loose/low coupling between data access logic, transaction management logic and business logic code.

Business object model classes containing business logic should not have data access code mixed in with the business logic. Data access logic involves much more than ".save" or ".persist" methods.

Ideally, business objects should have zero syntax-level dependencies upon commercial or open-source frameworks.

It is poor design and bad form to not have a DAO layer. The reasons and rationales are spelled out in documentation for the Data Access Object design pattern.
jQuery in Action, 2nd edition
subject: Do we need DAO layer