Skip to content

Spring Data JPA incorrectly derives query for custom base repository method getObj, causing "No property 'getObj' found for type 'User'" #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

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions