【发布时间】:2021-11-19 01:09:39
【问题描述】:
我有这门课:
public class UsersXCountry {
Integer numUsers;
String countryCode;
}
这个查询:
@Query(value = "select count('1'), country_code from t_user group by country_code",
nativeQuery = true)
List<UsersXCountry> usersXCountry();
但我有这个错误
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)
【问题讨论】:
-
UsersXCountry不是 Spring JPA 类? -
您无法使用本机查询将单个列直接选择到自定义对象类中。如果您想这样做,请使用
interface而不是class,或使用@NamedNativeQuery和@SqlResultSetMapping将结果映射到自定义对象类。
标签: java spring-boot jpa spring-data-jpa