Let's say that i have two Classes: Subject and Client, Subject is base-class.

public class Client extends Subject

Now i want to add customized Jpa base interface, so methods will be accessible in subinterfaces:

public interface SubjectRepository <T extends Subject> extends 
JpaRepository<T, Long>, CustomSubjectRepository<T> {}

CustomSubjectRepository looks like:

public interface CustomSubjectRepository<T extends Subject> {
    void saveEncrypted(T subject);

I need implementation so i declare class:

public class CustomSubjectRepositoryImpl<T extends Subject> implements 
CustomSubjectRepository<T> {

private EntityManager entityManager;

public void saveEncrypted(T subject) {

Then wanted to create ClientRepository and inherit from SubjectRepository to have access to saveEncrypted method.

public interface ClientRepository extends SubjectRepository<Client> {

But when it comes to compile i get:

Error creating bean with name 'clientRepository': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Failed to create query for method public abstract void com.path.repositories.CustomSubjectRepository.saveEncrypted(com.path.models.Subject)! No property saveEncrypted found for type Client!

1 Answers

vladwoguer On

You are extending the interface, this way Spring will try to create a query named saveEncrypted instead of using the customized method.

I believe the best solution is to extend the class CustomSubjectRepositoryImpl.

public class ClientRepository extends CustomSubjectRepositoryImpl<Client> {