`JpaRepository#getReferenceById(ID id)` recipe didn't replace all `getById()` method calls
What version of OpenRewrite are you using?
I am using the latest version, probably 8.42.0
How are you running OpenRewrite?
I am using the Maven Command Line, and my project is a single module project, not public.
mvn -U org.openrewrite.maven:rewrite-maven-plugin:run -Drewrite.recipeArtifactCoordinates=org.openrewrite.recipe:rewrite-spring:RELEASE -Drewrite.activeRecipes=org.openrewrite.java.spring.data.UseJpaRepositoryGetReferenceById -Drewrite.exportDatatables=true
What is the smallest, simplest way to reproduce the problem?
A project with JPA interfaces with or without an inheritance on JpaSpecificationExecutor<Company>.
public interface JPACompany extends JpaRepository<Company, Long>,
JpaSpecificationExecutor<Company> {
// some methods...
}
@RequiredArgsConstructor
@Component
public class Foo {
private final JPACompany jpaCompany;
public Company getCompany(Long id) {
return jpaCompany.getById(id));
}
}
What did you expect to see?
@RequiredArgsConstructor
@Component
public class Foo {
private final JPACompany jpaCompany;
public Company getCompany(Long id) {
return jpaCompany.getReferenceById(id));
}
}
What did you see instead?
JPA method getById wasn't replaced.
What is the full stack trace of any errors you encountered?
No errors.
Are you interested in contributing a fix to OpenRewrite?
Yes, I can try to help with some guidance.
hi @rogeriofrsouza ; thanks for the report & offer to help. The best way to get started is with a draft PR containing an additional test, adjusting this reference test to match the situation you're seeing: https://github.com/openrewrite/rewrite-spring/blob/471d2f8cca36abec95fca183d70ee3db5598f6c8/src/testWithSpringBoot_2_7/java/org/openrewrite/java/spring/data/UseJpaRepositoryGetReferenceByIdTest.java#L36-L79
Then we can from there look to see if there's any adjustments we need to make to the recipe: https://github.com/openrewrite/rewrite-spring/blob/471d2f8cca36abec95fca183d70ee3db5598f6c8/src/main/resources/META-INF/rewrite/spring-data-27.yml#L29-L40
If you're finding you can not reproduce the issue with a unit test, then it might make sense to have a look at alternative causes: https://docs.openrewrite.org/reference/faq#my-recipe-runs-but-is-not-making-any-changes-whats-happening