首页 > 解决方案 > Spring Data JPA 选择不同的列可分页

问题描述

我想根据不为空的列选择不同的记录并返回一个页面。以下是抛出 java.sql.SQLSyntaxErrorException: ORA-01791: not a SELECTed expression。

(如果我能让这个工作,我想通过一些额外的列来选择不同的。)

@Query(value="SELECT DISTINCT pm.batchId from PrintManifest pm",
//            + "where pm.batchId is not null"
        countQuery = "select count(DISTINCT pm.batchId) from PrintManifest pm",
        nativeQuery = true
)
Page<PolicyPrintManifest> findDistinctBatchId(Pageable pageable);

我也试过没有运气:

Page<PolicyPrintManifest> findDistinctByBatchIdExists(Pageable pageable);

执行此查询的正确方法是什么?

标签: javaspring-data-jpa

解决方案


是表或实体的 PrintManifest 名称。请记住,在本机查询中,您必须使用表名而不是实体名


推荐阅读