jQuery in Action, 2nd edition*
The moose likes OO, Patterns, UML and Refactoring and the fly likes Domain, DAO and Service layers question 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 "Domain, DAO and Service layers question" Watch "Domain, DAO and Service layers question" New topic
Author

Domain, DAO and Service layers question

Mike S. Chan
Greenhorn

Joined: May 31, 2013
Posts: 1
I am trying to build a small web application to manage my clients data and issue invoices using Spring and Hibernate. After reading a book on Spring MVC, hibernate and few articles I noticed many recommending to follow the (Domain, DAO and Service layers) model.

So I was wondering if this is really the best practice? and if yes, I am wondering what type of methods should be inside each layer (Domain, DAO and Service)?

I also read that DAO layer is responsible for managing connection to DB, but since I am using Hibernate, then I can't figure what type of methods I will need to add in DAO layer?

Also I've read that Service layer is responsible for executing (calling) DAO and domain layer methods, so I was wondering if this is the main job of service layer?

I am sorry if my questions are dummy, I am new to this world so please excuse my ignorance

Thanks for your time

Richard Yhip
Greenhorn

Joined: Nov 08, 2010
Posts: 3
You have to start somewhere. This can be confusing and there's a lot of information which can be overwhelming.

The way I've used it is that I'll map my entity classes (domain objects) to database tables using Hibernate or any other ORM.

The way I've viewed the DAO layer is that it's more of a utility class. For example if you have an entity class called Person you could have a class called PersonDAO that performs functions like getting all of the Person rows from the database, finding a specific Person, modifying a Person, and deleting a Person. So basically the DAO layer will do the actual CRUD operations on your entity objects along with whatever functions you need.

The Service layer will end up using your DAOs. For example if you have a web app that lets you create a Person you could then use Spring MVC to delegate the person creation task to another class which could potentially do validation or other business logic and then ask the DAO to handle persistence.
 
GeeCON Prague 2014
 
subject: Domain, DAO and Service layers question