0
@Repository
public interface StudentRepository extends CrudRepository<Student, String>, CustomRepository<Student> {
}
@Repository
public interface EmployeeRepository extends CrudRepository<Employee,String> ,CustomRepository<Employee> {
}
@NoRepositoryBean
public interface CustomRepository<T>  {
List<Object> customFindAll(Map<String, Object> map);}
public abstract class CustomRepositoryImpl<E, T> implements CustomRepository<T> {

  private JdbcTemplate jdbcTemplate;

  @Autowired 
  CustomRepositoryImpl(JdbcTemplate jdbcTemplate){
    this.jdbcTemplate = jdbcTemplate;
  }
  
  @Override
  public  List<Object> customFindAll(Map<String, Object> params) {

    //dynamic query goes here 
    return List<Object>
  }

Getting Exception;

Caused by: org.springframework.data.repository.query.QueryCreationException: Could not create query for public abstract java.util.List EE.custom.repo.CustomRepository.customFindAll(java.util.Map); Reason: No property 'customFindAll' found for type 'Employee'; nested exception is org.springframework.data.mapping.PropertyReferenceException: No property 'customFindAll' found for type 'Employee'

It is trying to find customFindAll as a property in my Employee dao but it's a custom method name not a property.

Any help , how to handle Generic CustomRepository with Custom methods for dynamic Queries in spring data jdbc.

Referred

https://docs.spring.io/spring-data/data-commons/docs/2.3.4.RELEASE/reference/html/#repositories.custom-implementations

pfurbacher
  • 1,789
  • 3
  • 15
  • 23
jimp a
  • 1

1 Answers1

0

Any help , how to handle Generic CustomRepository with Custom methods for dynamic Queries in spring data jdbc.

By default, you have to follow the naming of Spring Data to add custom methods through custom interface and implementation classes.


interface EmployeeRepository extends CrudRepository<Employee, Long>,
 EmployeeRepositoryCustom{}


//by default the custom interface must be with a `Custom` postfix
interface EmployeeRepositoryCustom{
    customFindAll()
}

// by default the implementation class name must be ended with a `Impl`
class EmployeeRepositoryImpl implements EmployeeRepositoryCustom{
    customFindAll(){ ...}
}

Of course you can update Spring Data configuration to change this freely when you are familiar with it.

Hantsy
  • 8,006
  • 7
  • 64
  • 109