Showing posts with label Java Generic DAO Hibernate Spring Design patterns. Show all posts
Showing posts with label Java Generic DAO Hibernate Spring Design patterns. Show all posts

Thursday, July 1, 2010

How to create a generic Dao with Hibernate and Spring Framework

When you are designing web applications a common problem to solve is the DAO (Data Access Object) layer. The simpler way to implement a DAO layer with Hibernate in seconds is to use some of the classes that are provided with Hibernate such as HibernateTemplate. HibernateTemplate class simplifies the data access operations when using Hibernate and provides an easy way to handle Hibernate Session objects .The following diagram shows in UML what is the rationale behind this implementation.


Image 1.  UML diagram for a generic DAO.


The solution proposed in this article is based on Spring Framework 2.5 and Hibernate 3.2.x. Let's begin with a business model class called Person, its objects (instances) are going to be used and obtained from a database like Oracle, MSSQL, or whatever JDBC compliant database