Skip to content

Custom base repository not considered for query method discovery when provided through a repository factory only #4093

@xiaobin8811

Description

@xiaobin8811

Summary

When defining a custom base repository interface plus implementation, Spring Data JPA attempts to derive a query from a non-derived method name and fails with:

No property 'getObj' found for type 'User'

Environment

  • Spring Boot: 4.0.0
  • Java: 25
  • OS: macOS

Code Snippet

@SpringBootApplication
@EnableJpaRepositories(
    basePackages = "com.example.demo.dao",
    repositoryFactoryBeanClass = CustomBaseRepositoryFactoryBean.class
)
public class DemoApplication {
    public static void main(String[] args) {
        SpringApplication.run(DemoApplication.class, args);
    }
}

@NoRepositoryBean
public interface BaseDao<T, ID extends Serializable>
        extends JpaRepository<T, ID>, JpaSpecificationExecutor<T> {
    T getObj(ID id);
}

public class BaseDaoImpl<T, ID extends Serializable>
        extends SimpleJpaRepository<T, ID>
        implements BaseDao<T, ID> {

    private final EntityManager entityManager;

    public BaseDaoImpl(JpaEntityInformation<T, ?> entityInformation,
                       EntityManager entityManager) {
        super(entityInformation, entityManager);
        this.entityManager = entityManager;
    }

    @Override
    public T getObj(ID id) {
        return findById(id).orElse(null);
    }
}

User repository:

public interface UserDao extends BaseDao<User, Long> {}

Observed Behavior

Application fails to start with:

org.springframework.beans.factory.UnsatisfiedDependencyException: ...
No property 'getObj' found for type 'User'

Metadata

Metadata

Assignees

Labels

status: declinedA suggestion or change that we don't feel we should currently apply

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions