Reputation: 4361
I am trying to provide a Custom Implementation of repository using Spring Data JPA. I have :
public interface PersonRepositoryCustom{
List<Person> chercher(String name);
}
And the implementation :
public class PersonRepositoryImpl implements PersonRepositoryCustom{
List<Person> chercher(String name){
// my implementation
}
}
The two classes are in the jpa:repositories package
Here is my Person DAO:
public interface IPersonDAO extends CrudRepository<Person, Long>,PersonRepositoryCustom{
// other methods here
}
When i launch the server i am getting the error :
org.springframework.data.mapping.PropertyReferenceException: No property chercher found for type Person
at org.springframework.data.mapping.PropertyPath.<init>(PropertyPath.java:75)
at org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:327)
at org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:307)
at org.springframework.data.mapping.PropertyPath.from(PropertyPath.java:270)
at org.springframework.data.mapping.PropertyPath.from(PropertyPath.java:241)
at org.springframework.data.repository.query.parser.Part.<init>(Part.java:76)
at org.springframework.data.repository.query.parser.PartTree$OrPart.<init>(PartTree.java:201)
at org.springframework.data.repository.query.parser.PartTree$Predicate.buildTree(PartTree.java:291)
at org.springframework.data.repository.query.parser.PartTree$Predicate.<init>(PartTree.java:271)
at org.springframework.data.repository.query.parser.PartTree.<init>(PartTree.java:80)
at org.springframework.data.jpa.repository.query.PartTreeJpaQuery.<init>(PartTreeJpaQuery.java:57)
at org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$CreateQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:91)
at org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$CreateIfNotFoundQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:162)
at org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$AbstractQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:69)
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.<init>(RepositoryFactorySupport.java:304)
at org.springframework.data.repository.core.support.RepositoryFactorySupport.getRepository(RepositoryFactorySupport.java:161)
at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.initAndReturn(RepositoryFactoryBeanSupport.java:224)
at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.afterPropertiesSet(RepositoryFactoryBeanSupport.java:210)
at org.springframework.data.jpa.repository.support.JpaRepositoryFactoryBean.afterPropertiesSet(JpaRepositoryFactoryBean.java:84)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1612)
Upvotes: 3
Views: 3401
Reputation: 4361
I've found the answer. Spring-data-jpa use a convention to write CustomRepository. To achieve this task : we have to have as explained in the Spring Data JPA documentation . We have to create a interface in which we add custom method :
public interface PersonRepositoryCustom{
List<Person> chercher(String name);
}
Suppose we have following DAOService :
public interface IPersonDAO extends CrudRepository<Person, Long>,PersonRepositoryCustom{
// other methods here
}
So the implementation of custom repository is :IPersonDAOImpl
public class IPersonDAOImpl implements PersonRepositoryCustom{
List<Person> chercher(String name){
// my implementation
}
}
And not PersonRepositoryImpl
I hope this will help.
Upvotes: 9