Skip to content

JpaRepository#getReferenceById(ID id) recipe didn't replace all getById() method calls #658

Open
@rogeriofrsouza

Description

@rogeriofrsouza

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    Backlog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions