Not found in annotated query error with @Query

I am using spring data with REST. I have a table and a corresponding entity called Country.java

I have annotated my method in CountryRepositopry as

public interface CountryRepository extends Repository<Country, Short> {

    @RestResource(path = "bycode3")
        @Query("select c from Country c where c.codeAlpha3=?1 and c.active=1")
        Country findCountryByCodeAlpha3(@Param("code") String countryCode);
 }

      

I am getting the following exception when starting tomcat -

Caused by: java.lang.IllegalStateException: Using named parameters for method public abstract com.persistence.entity.common.Country com.persistence.repository.CountryRepository.findCountryByCodeAlpha3(java.lang.String) but parameter 'code' not found in annotated query 'select c from Country c where c.codeAlpha3=?1 and c.active=1'!

      

+3


source to share


2 answers


I got fixed

The request needs to be changed as



@Query("select c from Country c where c.codeAlpha3=:code and c.active=1") 

      

Instead of ? 1 it should be : code

+8


source


Text xxx

in @Param("xxx")

must be used in Query value

.



0


source







All Articles