【发布时间】:2019-12-14 09:28:08
【问题描述】:
在尝试使用 Query 获取数据并暴露为 API 获取异常时
@Repository
public interface EmployeeRepository extends JpaRepository<Employee,
String> {
@Query(value="Select * from Employee",nativeQuery = true)
@RestResource(path = "byEmp", rel = "byEmp")
List<Map> findTest();
}
网址:http://localhost:8080/employeeEntities/search/byEmp
例外:
java.lang.IllegalArgumentException: Couldn't find PersistentEntity for type class org.springframework.data.jpa.repository.query.AbstractJpaQuery$TupleConverter$TupleBackedMap!
at org.springframework.data.mapping.context.PersistentEntities.lambda$getRequiredPersistentEntity$2(PersistentEntities.java:78) ~[spring-data-commons-2.0.13.RELEASE.jar:2.0.13.RELEASE]
at java.util.Optional.orElseThrow(Optional.java:290) ~[na:1.8.0_181]
at org.springframework.data.mapping.context.PersistentEntities.getRequiredPersistentEntity(PersistentEntities.java:77) ~[spring-data-commons-2.0.13.RELEASE.jar:2.0.13.RELEASE]
at org.springframework.data.rest.webmvc.PersistentEntityResourceAssembler.wrap(PersistentEntityResourceAssembler.java:72) ~[spring-data-rest-webmvc-3.0.13.RELEASE.jar:3.0.13.RELEASE]
at org.springframework.data.rest.webmvc.PersistentEntityResourceAssembler.toResource(PersistentEntityResourceAssembler.java:55) ~[spring-data-rest-webmvc-3.0.13.RELEASE.jar:3.0.13.RELEASE]
at org.springframework.data.rest.webmvc.AbstractRepositoryRestController.entitiesToResources(AbstractRepositoryRestController.java:110) ~[spring-data-rest-webmvc-3.0.13.RELEASE.jar:3.0.13.RELEASE]
at org.springframework.data.rest.webmvc.AbstractRepositoryRestController.toResources(AbstractRepositoryRestController.java:80) ~[spring-data-rest-webmvc-3.0.13.RELEASE.jar:3.0.13.RELEASE]
at org.springframework.data.rest.webmvc.RepositorySearchController.lambda$toResource$1(RepositorySearchController.java:209) ~[spring-data-rest-webmvc-3.0.13.RELEASE.jar:3.0.13.RELEASE]
at java.util.Optional.map(Optional.java:215) ~[na:1.8.0_181].at org.springframework.data.rest.webmvc.RepositorySearchController.toResource.
如果我尝试通过创建方法从任何其他类调用我能够获取记录
【问题讨论】:
标签: spring-boot spring-data-jpa spring-data-rest