Databases Reference
In-Depth Information
2.
Make the created class extend the JpaRepositoryFactory class.
3.
Override the getTargetRepository() method of the
JpaRepositoryFactory class. This method is responsible for creating the
actual repository implementations.
4.
Override the getRepositoryBaseClass() method of the
JpaRepositoryFactory class, which simply returns the class of the
base repository implementation. We can ignore the metadata given as a
parameter because that information is used by the JpaRepositoryFactory
to decide whether it should return the SimpleJpaRepository or
QueryDslJpaRepository class.
The source code of the repository factory inner class is given as follows:
protected static class BaseRepositoryFactory<T, I extends
Serializable> extends JpaRepositoryFactory {
private EntityManager entityManager;
public BaseRepositoryFactory(EntityManager entityManager) {
super(entityManager);
this.entityManager = entityManager;
}
@Override
protected Object getTargetRepository(RepositoryMetadata metadata)
{
return new GenericBaseRepository<T,
I>((JpaEntityInformation<T,I>) getEntityInformation(metadata.
getDomainType()), entityManager);
}
@Override
protected Class<?> getRepositoryBaseClass(RepositoryMetadata
metadata) {
return GenericBaseRepository.class;
}
}
 
Search WWH ::




Custom Search