我只想向客户端返回我的数据的一个子集。例如,使用投影。一些文档暗示查询可以返回投影,但我得到了如下所示的错误。如果我更改查询以返回supplier实体,则一切正常。
java.lang.IllegalArgumentException: PersistentEntity must not be null!
查询:
Page<SupplierLookupProjection> findByApSupplierCodeContainsIgnoreCaseOrAdminAddressContainsIgnoreCaseOrderByApSupplierCodeAsc(Pageable pageable, @Param("code") String code, @Param("description") String description);
存储库:
public interface SupplierRepository extends PagingAndSortingRepository<Supplier, Long>
发布于 2016-09-12 19:28:15
如果不了解SupplierLookupProjection是如何实现的,我相信您可能会错过将SupplierLookupProjection定义为投影接口的过程。
如果是这样,请使用感兴趣的字段的getters将SupplierLookupProjection定义为投影接口。
例如:假设您只需要Supplier的name和location字段,则可以仅使用这些getter定义投影接口,如下所示:
interface SupplierLookupProjection {
String getName();
String getLocation();
}你可以参考Spring Data JPA projections来获得更多的例子。
https://stackoverflow.com/questions/39448972
复制相似问题