Database Support in Spring
by, 11-16-2011 at 05:40 PM (1983 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.
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.