My base repo interface looks something like this:
Code:
@Repository
public interface EmployeeRepository extends JpaRepository<Employee, String>,
QueryDslPredicateExecutor<Employee>,
EmployeeRepositoryCustom {
Page <Employee> findByOrgId(String orgId, Pageable pageable);
}
My custom extension to the base looks something like so:
Code:
public interface EmployeeRepositoryCustom {
Page<Employee> findByGroupId(EmployeeGroup employeeGroup, Pageable pageable);
}
Like you, in my implementation of EmployeeRepositoryCustom, I'd like to use support from EmployeeRepository.
Code:
@Repository
public class EmployeeRepositoryImpl implements EmployeeRepositoryCustom {
@PersistenceContext private EntityManager em; // I get that I can easily use the lower level entity manager
@Autowired private EmployeeRepository employeeRepository; // but I'd also like to use this
@Override
public Page<Employee> findByGroupId(EmployeeGroup employeeGroup, Pageable pageable) {
Predicate predicate = QEmployee.employee.employeeGroups.contains(employeeGroup);
return employeeRepository.findAll(predicate, pageable);
}
}
But doesn't this introduce a circular reference? Depending on how I fiddle things results in a NullPointerException (happens when I annotate EmployeeRepositoryImpl with @Service) or a BeanCurrentlyInCreationException (happens when I annotate EmployeeRepositoryImpl with @Repository).
How did you manage to get this working?
I've had a look at the docs and samples which are very good but don't seem to go over this particular usage. Although... this sample does say if I need to inject something in my custom repo implementation, I'll need to manually do so.
Thanks,
-Lee-