简体   繁体   English

Spring 数据 JPA Select 不同的列可分页

[英]Spring Data JPA Select Distinct Column Pageable

I'd like to select distinct records based on a column where not null and return a page.我想 select 基于非 null 的列的不同记录并返回一个页面。 The following is throwing java.sql.SQLSyntaxErrorException: ORA-01791: not a SELECTed expression.以下是抛出 java.sql.SQLSyntaxErrorException: ORA-01791: not a SELECTed expression。

(If I can get this to work I'd like to select distinct by a few additional columns.) (如果我能让这个工作,我想 select 与其他几列不同。)

@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);

I also tried with no luck:我也试过没有运气:

Page<PolicyPrintManifest> findDistinctByBatchIdExists(Pageable pageable);

What's the right way to do this query?执行此查询的正确方法是什么?

Is PrintManifest name of the table or the entity.是表或实体的 PrintManifest 名称。 Remember that in native query, you have to use table name not entity name请记住,在本机查询中,您必须使用表名而不是实体名

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM