Results 1 to 7 of 7

Thread: DAO design pattern

  1. #1
    Join Date
    Mar 2011
    Posts
    7

    Default DAO design pattern

    I'm just embarking on a new project and I'm kind of new to the hibernate/spring integration side of things and was just wondering what the best DAO design pattern would be that would suit hibernate integration.

    At the moment I'm thinking DAO interface for each domain object and then inherit from that as HibernateDAO along with subclassing the HibernateDAOSupport class.

    One thing I don't know is that I noticed that the domain objects produced from the DAO all have mutators and accessors on them so that Hibernate can access their properties to persist them but what happens if I want to keep the properties of my domain objects encapsulated? Should I put a wrapper around the entities and make that be the true domain object?

    Any help or guidance would be appreciated a lot! Thanks for your time.

  2. #2
    Join Date
    Aug 2006
    Location
    Arequipa-Peru / South America
    Posts
    2,796

    Default

    Hello

    Take a look here
    So should you still use Spring's HibernateTemplate and/or JpaTemplate??

    Normally for each class or entity I create its own DAO class with the CRUD methods, save, create, find, etc, of course each class must implement its own interface since Spring work strongly with the Proxy Pattern
    - Manuel Jordan

    Kill Your Pride, Share Your Knowledge With All
    The Fear Of The LORD Is The Beginning Of Knowledge, But Fools Despise Wisdom And Discipline. Proverbs 1:7

    Blog


    Technical Reviewer of Apress

    • Pro SpringSource dm Server
    • Spring Enterprise Recipes: A Problem-Solution Approach
    • Spring Recipes: A Problem-Solution Approach, 2nd Edition
    • Pro Spring Integration
    • Pro Spring Batch
    • Pro Spring 3
    • Pro Spring MVC: With Web Flow
    • Pro Spring Security

  3. #3
    Join Date
    Mar 2011
    Posts
    7

    Default

    Ah thanks but for each entity does that entity hold business logic - like a domain object or does it simply have getters and setters for each field and the domain object wraps around it?

  4. #4
    Join Date
    Aug 2006
    Location
    Arequipa-Peru / South America
    Posts
    2,796

    Default

    I work in this way

    An Entity has basically its:

    • constructor
    • setter/getters accessors methods
    • toString method
    • add/remove methods to add/remove an element from a Collection (for example the Set collection to add or remove a Child)


    lets call for example Customer to some Entity

    Therefore the MVC architecture/pattern should be (a general idea - some terms or semantics could vary slightly)

    CustomerController-->CustomerBO-->CustomerDAO-->Customer


    CustomerBO Should has the Business methods
    CustomerDAO must has only the CRUD methods

    I suggest you read more about the MVC, without a clear understanding of this important architecture you would do a bad application
    - Manuel Jordan

    Kill Your Pride, Share Your Knowledge With All
    The Fear Of The LORD Is The Beginning Of Knowledge, But Fools Despise Wisdom And Discipline. Proverbs 1:7

    Blog


    Technical Reviewer of Apress

    • Pro SpringSource dm Server
    • Spring Enterprise Recipes: A Problem-Solution Approach
    • Spring Recipes: A Problem-Solution Approach, 2nd Edition
    • Pro Spring Integration
    • Pro Spring Batch
    • Pro Spring 3
    • Pro Spring MVC: With Web Flow
    • Pro Spring Security

  5. #5
    Join Date
    Mar 2011
    Posts
    7

    Default

    Ah thanks so from my understanding the CustomerController and the CustomerBO is the controller, the CustomerDAO and the Customer represents the model and any GUI stuff like panels and dialogs would be the view.

  6. #6
    Join Date
    Jul 2011
    Posts
    1

    Default

    Hibernate's goal is to relieve the developer from 95 percent of common data persistence related programming tasks. Hibernate may not be the best solution for data-centric applications that only use stored-procedures to implement the business logic in the database, it is most useful with object-oriented domain models and business logic in the Java-based middle-tier. However, Hibernate can certainly help you to remove or encapsulate vendor-specific SQL code and will help with the common task of result set translation from a tabular representation to a graph of objects.

  7. #7
    Join Date
    Mar 2011
    Posts
    7

    Default

    Quote Originally Posted by ajans View Post
    Hibernate's goal is to relieve the developer from 95 percent of common data persistence related programming tasks. Hibernate may not be the best solution for data-centric applications that only use stored-procedures to implement the business logic in the database, it is most useful with object-oriented domain models and business logic in the Java-based middle-tier. However, Hibernate can certainly help you to remove or encapsulate vendor-specific SQL code and will help with the common task of result set translation from a tabular representation to a graph of objects.
    Why have you copy and pasted paragraph 3 of http://docs.jboss.org/hibernate/core...l/preface.html ? It has no relevance other than the fact it's related to Hibernate.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •