This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
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
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.