• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Domain, DAO and Service layers question

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
He does not suffer fools gladly. But this tiny ad does:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic