• 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

Should it be one DAO per entity?

 
Ranch Hand
Posts: 157
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
In my project the persistance layer is implemented in such a way that one DAO per service. For example GenerateCSVDao for csv generation service and so. This DAO may access more than one table and may handle more than one entity.
Now i was asked to refactor the dao layer to make use of Generics. When I gone though the hibernate site for DAO patterns using Generics, DAO's declaration is like CustomerHibernateDao<Customer, custId>.

My doubt is Generic DAO pattern applicable only when one DAO per entitiy cases?
Can't i make use of Generics in my project? if so how?

Thanks in advance,
Bala.
 
author & internet detective
Posts: 41919
910
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Bala,
DAOs can be, but don't have to be, one per entity.

The person who asked you to use generics might have meant on a method level rather than a class level. For example, DAOs frequently query for a list of something. You could return List<Customer> rather than List.
 
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Bala

In many cases each entity needs its own DAO. However, when possible have your DAO objects deal with components of objects. For example, you want a DAO for an Invoice class but you probably don't want a DAO for the related LineItem class. Deal with the LineItem objects only as part of Invoice obect itself, ie save the LineItems objects by saving the Invoice object. If you have a DAO for every entity you are probably dealing with an Anemic Domain Model.
 
reply
    Bookmark Topic Watch Topic
  • New Topic