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

@Entity
public class Client extends Subject

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

@NoRepositoryBean
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:

@Repository
@Transactional
public class CustomSubjectRepositoryImpl<T extends Subject> implements 
CustomSubjectRepository<T> {

@PersistenceContext
private EntityManager entityManager;

@Override
public void saveEncrypted(T subject) {
    //implementation
}
}

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

@Repository
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

0
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.

@Repository
public class ClientRepository extends CustomSubjectRepositoryImpl<Client> {
}