-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Inject Repository into RepositoryCustom #2384
Comments
In short, this isn't possible as repository fragments are required to create the repository instance. You can either work around it by using |
What's the correct approach to address this problem without using the workarounds above ? What if the fragment needs the repository as mentioned by @niroussel ?
|
Maybe one of:
|
I've this workaround @Repository
public class UserRepositoryImpl implements UserRepositoryCustom {
@PersistenceContext
private EntityManager entityManager;
private JpaSpecificationExecutor<User> executor;
@PostConstruct
public void init() {
executor = new SimpleJpaRepository<User, String>(User.class, entityManager);
}
@Override
public List<User> searchByCriteria(UserSearchCriteria searchCriteria) {
return executor.findAll(UserSpecifications.build(searchCriteria));
}
}
i think the query logic should be kept in the repository layer; should not be leaked to the service layer. |
Until SpringBoot 2.4.1, it was possible to inject a repository into its custom implementation.
This was really useful to avoid having several repositories for the same Entity.
For example, this doesn't work anymore:
With :
This will lead to this exception:
The text was updated successfully, but these errors were encountered: