简体   繁体   中英

Spring JPArepository Exeption with query method

I have a problem when i implement this method in my ClientRepository :

public interface ClientRepository extends JpaRepository<Client,Long> {
    @Query("select n from Client where n.nom like :x")
    public Page<Client> chercher(@Param("x") String mc , Pageable pageable);
}

Exeption: Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled. 2018-05-23 10:33:32.606 ERROR 15048 --- [ restartedMain] osboot.SpringApplication : Application run failed

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'maBanqueApplication': Unsatisfied dependency expressed through field 'clientRepository'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'clientRepository': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Validation failed for query for method public abstract org.springframework.data.domain.Page org.sid.Dao.ClientRepository.chercherClient(java.lang.String,org.springframework.data.domain.Pageable)! at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:587) ~[spring-beans-5.0.5.RELEASE.jar:5.0.5.RELEASE] at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:91) ~[spring-beans-5.0.5.RELEASE.jar:5.0.5.RELEASE]

Your query is wrong:

@Query("select n from Client where n.nom like :x") // You select `n` from no where

Change it to

@Query("select n from Client n where n.nom like :x")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM