Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Not found in annotated query error with @Query

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'!
like image 494
Vijay Kumar Rajput Avatar asked Oct 24 '14 22:10

Vijay Kumar Rajput


2 Answers

The text xxx in @Param("xxx") must be used in Query value.

like image 83
Tiina Avatar answered Dec 17 '22 17:12

Tiina


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

like image 23
Vijay Kumar Rajput Avatar answered Dec 17 '22 17:12

Vijay Kumar Rajput