Closed
Description
What problem are you trying to solve?
As of Springboot v2.7, both getOne()
and getById()
methods have been deprecated for JpaRepository
. The documentation states that these deprecated methods should be replaced with getReferenceById(ID)
.
We should include this recipe for Spring 2.7, for example:
type: specs.openrewrite.org/v1beta/recipe
name: org.openrewrite.java.spring.data.UseJpaRepositoryGetReferenceById
displayName: Use `JpaRepository#getReferenceById(ID id)`
description: '`JpaRepository#getById(ID)` was deprecated in 2.7.'
recipeList:
- org.openrewrite.java.ChangeMethodName:
methodPattern: org.springframework.data.jpa.repository.JpaRepository getById(..)
newMethodName: getReferenceById
Describe the situation before applying the recipe
import org.springframework.data.jpa.repository.JpaRepository;
public interface TestRepository extends JpaRepository<Test, Long> {
}
public Test getTestById(final long id) {
return testRepository.getOne(id);
}
Describe the situation after applying the recipe
import org.springframework.data.jpa.repository.JpaRepository;
public interface TestRepository extends JpaRepository<Test, Long> {
}
public Test getTestById(final long id) {
return testRepository.getReferenceById(id);
}
Have you considered any alternatives or workarounds?
N/A
Are you interested in contributing this recipe to OpenRewrite?
Metadata
Metadata
Assignees
Labels
Type
Projects
Status
Done