For the past 18 months I have been utilizing hades for implementing JPA based repositories/DAOs. Hades has now been moved into the Spring Data JPA project. Starting with their 1.0.1 release I tried migrating one of my projects to this release. Following I document the steps that were necessary to achieve this.

Their project page starts off with showing the Maven repositories and dependency descriptors (in case you are using Maven). Obviously the first thing is to replace the hades artifact by the spring-data-jpa artifact.

The project’s domain classes implement the org.synyx.hades.domain.Persistable interface which has to be replaced by org.springframework.data.domain.Persistable (takes a single generics parameter for the id type).

DAO interfaces extending org.synyx.hades.dao.GenericDao have to be modified to extend org.springframework.data.repository.CrudRepository. With this modification you will face a couple of compile problems. read*-methods have been renamed to find*-methods. Also you are loosing the paging and sorting capable find* - methods (which I didn’t use). If those are required then extend the org.springframework.data.repository.PagingAndSortingRepository interface.

find* - methods now return iterables rather than list types requiring minor adjustments to existing codebase. To get around this, the interface can also extend from JpaRepository. Using this base interface hands you a pretty powerful DAO that goes far beyond a simple CRUD repository.

When I started off with hades many month ago I used an explicit XML-based configuration of DAO components.

1
<bean id="addressDao" class="org.synyx.hades.dao.orm.GenericDaoFactoryBean" p:daoInterface="at.martinahrer.training.spring.jpa.dao.hades.AddressDao" />

For migration the factory bean class has to be changed:

1
<bean id="addressDao" class="org.springframework.data.jpa.repository.support.JpaRepositoryFactoryBean" p:daoInterface="at.martinahrer.training.spring.jpa.dao.hades.AddressDao" />

With these changes in place all tests were showing the green bar again. However, today I would recommend using repository namespace http://www.springframework.org/schema/data/jpa which significantly reduces the amount of configuration needed by utilizing class path scanning to detect repository components.

1
<repository:repositories base-package="at.martinahrer.training.spring.jpa.dao" />

Certainly you might encounter more steps during migration depending on the features you have used from the old hades code base. In my case I only had used named JPA queries which just continued to work like before.

Comments