I am using spring data with REST. I have a table country and an Entity corresponding to it 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 following exception while 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'!
The text xxx
in @Param("xxx")
must be used in Query value
.
I got the fixed
Query needs be modified as
@Query("select c from Country c where c.codeAlpha3=:code and c.active=1")
Instead of ?1 it should be :code
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With