Is it good to have reference to JPARepositry when implementing Custom Repository?
For example, imagine that I have repository for my entity:
@Repository
public interface EntityRepository extends JPARepository<Entity, Long> {
}
And I want to add some custom method which works as a wrapper to findById. According to the tutorial, to implement custom logic to my repository I have to define custom interface and EntityRepository should extend it:
public interface EntityCustomRepository {
Optional<Entity> findByIdWithFilters();
}
Changes in EntityRepository:
@Repository
public interface EntityRepository extends JPARepository<Entity, Long>, EntityCustomRepository {
}
And also I should provide implementation for my custom repository:
public EntityCustomRepositoryImpl implements EntityCustomRepository{
@Inject
private EntityRepository repository;
@Override
public Optional<Entity> findByIdWithFilters() {
// enable filters to the session
Optional<Entity> result = this.findById();
// disable filters
return result;
}
}
As you can see my custom repository works like proxy to EntityRepository, so is there any better solution to implement it? Or keeping in custom repositories reference to main repository is also good practise and there is nothing to improve?