【发布时间】:2019-08-31 22:56:32
【问题描述】:
在我的 JpaRepository 界面中,我得到了以下可以正常工作的方法:
Page<PermissionRule> findByOrganizationIdAndTypeStringAndObjectReferenceIgnoreCaseContaining(
Long organizationId, String typeId, String searchTerm, Pageable pageable);
我需要的是通过 object_reference 分组的相同查询。
这是我尝试做的: 编辑
@Query(value = "SELECT object_reference, dst_type, other FROM permission_rule pr WHERE pr.organization_id = %?1% AND pr.dst_type_id = %?2% AND pr.object_reference LIKE %?3% GROUP BY object_reference", nativeQuery = true)
Page<PermissionRule> getFunds(Long organizationId, String dstTypeId, String searchTerm, Pageable pageable);
但我收到以下错误
InvalidJpaQueryMethodException:无法在方法中使用具有动态排序和/或分页的本机查询
另外,如果它有助于我想在 GROUP BY 中使用的实体列是
@Column(name = "object_reference", nullable = false)
private String objectReference;
我的问题是是否有更简单的方法可以做到这一点,或者我仍然需要自定义查询(我是否需要在实体中移动自定义查询或使用命名查询?)?
【问题讨论】:
-
我觉得this link可以帮到你。
标签: java hibernate spring-data-jpa spring-data