Home > Back-end >  No converter found capable of converting from type
No converter found capable of converting from type

Time:09-27

I have this class:

public class UsersXCountry {

    Integer numUsers;
    String countryCode;

}

and this query:

@Query(value = "select count('1'), country_code from t_user group by country_code",
        nativeQuery = true)
List<UsersXCountry> usersXCountry();

but I have this error

No converter found capable of converting from type [org.springframework.data.jpa.repository.query.AbstractJpaQuery$TupleConverter$TupleBackedMap] to type [com.losmundo.backend.domain.UsersXCountry]
    at org.springframework.core.convert.support.GenericConversionService.handleConverterNotFound(GenericConversionService.java:322)

CodePudding user response:

The names must be identicals beside adding getters, setters to UsersXCountry

@Query(value = "select count('1') as numUsers, country_code as countryCode from t_user group by country_code",
        nativeQuery = true)
List<UsersXCountry> usersXCountry();
  • Related