DAO support and @Repository annotation

The standard way of accessing data is via specialized DAOs that perform persistence functions under the data access layer. Spring follows the same pattern by providing DAO components and allowing developers to mark their data-access components as DAOs, using the annotation @Repository. This approach ensures consistency over various data access technologies such as JDBC, Hibernate, JPA, and JDO, and project-specific repositories. Spring applies SQLExceptionTranslator across all these methods consistently.

Spring recommends your data-access components to be annotated with stereotype, @Repository. The term, repository, was originally defined in Domain-Driven Design, Eric Evans, Addison Wesley as "a mechanism for encapsulating storage, retrieval, and search behavior which emulates a collection of objects." This annotation makes the class eligible for DataAccessException translation by Spring Framework.

Spring Data, another standard data-access mechanism provided by Spring, revolves around @Repository components. We will discuss this more in later sections.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset