【发布时间】:2022-11-03 00:36:49
【问题描述】:
是否可以从表中选择一个或多个字段并将其映射到实体中?
目前正在尝试
@Repository
public interface RoleRepo extends JpaRepository<Role, Long>{
@Query("SELECT r.roleId, r.name FROM role r")
List<Role> getAllRoleNames();
}
我只想要这 2 个值,其余字段可以是 null 以提高效率。我现在得到的错误是
ConversionFailedException: Failed to convert from type [java.lang.Object[]] to type
[@org.springframework.data.jpa.repository.Query demo.model.Role] for value '{1, Java Dev}';
nested exception is org.springframework.core.convert.ConverterNotFoundException:
No converter found capable of converting from type [java.lang.Long] to type
[@org.springframework.data.jpa.repository.Query demo.model.Role]] with root cause
那么,当我不能只说object.Id = role.roleId(object.Id 就是1)时,我该如何进行转换。
【问题讨论】:
标签: java spring spring-boot jpa