View RSS Feed

Spring Framework

Database Support in Spring

Rate this Entry
by , 11-16-2011 at 06:40 PM (2355 Views)
In our next tip, I will focus on Spring’s data access support. Spring uses the design pattern, data access object (DAO). The purpose of DAOs is to provide means to read and write data to the database. So what Spring has focused on is to make it easy for developers to write DAOs as irrespective of whether you use JDBC, Hibernate, JPA or JDO. The way in which it does this is by separating the interface from the data access implementation. Therefore the implementation can change to align with the with type of data access you want to use. The nice thing about this is that you can easily test via mock implementation of the data access interfaces. So you can test the services that use data access objects as well as the data access objects themselves.

Name:  DatabaseAccess.jpg
Views: 1152
Size:  25.4 KB

As shown in the diagram, the chosen persistence approach is isolated to the DAO while only the relevant data access methods are exposed through the interface. In this design it is quite easy to swap from one implementation to another with minimal impact to your application.

Submit "Database Support in Spring" to Facebook Submit "Database Support in Spring" to Digg Submit "Database Support in Spring" to Submit "Database Support in Spring" to StumbleUpon Submit "Database Support in Spring" to Google

Hibernate , JDBC , JPA