在我的 JpaRepository 接口中,我得到了以下工作正常的方法:
Page<PermissionRule> findByOrganizationIdAndTypeStringAndObjectReferenceIgnoreCaseContaining(
Long organizationId, String typeId, String searchTerm, Pageable pageable);
我需要的是与 group by 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;
我的问题是是否有更简单的方法来做到这一点,或者我仍然需要自定义查询(我是否需要在实体中移动自定义查询或改用命名查询?)?