Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
138 C HAPTER 5 Hitting the database <context:component-scan base-package="com.habuma.spitter.persistence" /> In addition to helping to reduce XML -based configuration, @Repository serves another purpose. Recall that one of the jobs of a template class is to catch platform- specific exceptions and rethrow them as one of Spring's unified unchecked excep- tions. But if we're using Hibernate contextual sessions and not a Hibernate template, then how can the exception translation take place? To add exception translation to a template-less Hibernate DAO , we just need to add a PersistenceExceptionTranslationPostProcessor bean to the Spring applica- tion context: <bean class="org.springframework.dao.annotation. PersistenceExceptionTranslationPostProcessor"/> PersistenceExceptionTranslationPostProcessor is a bean post processor which adds an advisor to any bean that's annotated with @Repository so that any platform- specific exceptions are caught and then rethrown as one of Spring's unchecked data access exceptions. And now the Hibernate version of our DAO is complete. And we were about to develop it without directly depending on any Spring-specific classes (aside from the @Repository annotation). That same template-less approach can also be applied