Databases Reference
In-Depth Information
}
delete(deleted);
return deleted;
}
}
Creating the repository factory bean
Now that we have implemented the custom functionality, we have to ensure that it is
used when the concrete repository implementations are created. This means that we
have to create a custom repository factory bean that replaces the default repository
factory bean. Our repository factory bean has a single purpose: It will provide
GenericBaseRepository as an implementation of all interfaces extending the
Repository interface. We can create a custom repository factory bean by following
these steps:
1.
Create a skeleton of the repository factory bean class.
2.
Create a repository factory class.
3.
Create a builder method used to build new repository factories.
Creating the skeleton of the repository factory bean
class
First we have to create the repository factory bean class. This class must extend the
JpaRepositoryFactoryBean<R, T, I> class that is the default repository factory
bean of Spring Data JPA. This class has three type parameters: the type of the
repository, the type of the entity, and the type of the entity's ID. The source code of
the class skeleton is given as follows:
public class BaseRepositoryFactoryBean <R extends JpaRepository<T, I>,
T, I extends Serializable> extends JpaRepositoryFactoryBean<R, T, I> {
}
Creating the repository factory inner class
The second step is to create the actual repository factory class. The implementation of
this class includes the following steps:
1.
Add the BaseRepositoryFactory class as a protected inner class to the
BaseRepositoryFactoryBean class.
 
Search WWH ::




Custom Search