【问题标题】:How to get paginated result in Spring JPA repository using Oracle 10g如何使用 Oracle 10g 在 Spring JPA 存储库中获取分页结果
【发布时间】:2020-10-18 09:44:47
【问题描述】:

AI_DpEntriesRepository.java

public interface AI_DpEntriesRepository extends PagingAndSortingRepository<AI_DpEntries, Long>{

    @Query(value = "select a.*,m.description,m.name from AI_DPENTRIES a,"
            + "MEDICALHIERARCHY m where PAGEID in (select pageid from PAGES where caseid=8960)"
            + " and a.HID=m.ID",nativeQuery = true)
    Page<AI_DpEntries> getLabAIDpEntries(Pageable pageable);
}

AIDpEntryServiceImpl.java

public class AIDpEntryServiceImpl implements AIDpEntryService{
    
    @Autowired
    private AI_DpEntriesRepository aiDpEntryRepository;

    @Override
    @Cacheable("labdpentries")
    public Page<AI_DpEntries> getAIDpEntries(int page,int size) {
     Pageable pageRequest = PageRequest.of(page, 5);
     Page<AI_DpEntries> pageResult = aiDpEntryRepository.getLabAIDpEntries(pageRequest);
     List<AI_DpEntries> dpEntries = pageResult.getContent().stream().collect(Collectors.toList());
     return new PageImpl<>(dpEntries, pageRequest, pageResult.getTotalElements());
     //return aiDpEntryRepository.getLabAIDpEntries();
    }

}

获取 java.sql.SQLSyntaxErrorException: ORA-00904: "A": 无效标识符 从存储库调用本身。我究竟做错了什么?如果我将 size 参数值作为 Integer.MAX_VALUE 传递,它将当前一次返回所有记录。但我的要求是每页获得 5 条记录

【问题讨论】:

  • 请发布完整的堆栈跟踪(格式化为代码)和您的 JPA 实现实际尝试执行的日志中的 SQL 语句。
  • 已解决:此处需要计数查询以及存储库中的查询,它应该返回与查询方法返回的行相同的计数。
  • 请发布完整的答案,以便其他人可以从中受益。或者,请删除问题。
  • @JensSchauder 作为答案发布

标签: java spring spring-boot spring-data-jpa pagination


【解决方案1】:

此处的解决方案 - 需要计数查询以及返回相同编号的本机查询。由本机查询返回的行数(PS-询问问题的查询中的微小变化)

@Repository
public interface AI_DpEntriesRepository extends JpaRepository<AI_DpEntries, Long>{

@Query(value = "select a.*,m.description,m.name from AI_DPENTRIES a,
MEDICALHIERARCHY m where PAGEID in (select pageid from PAGES where caseid=8960) and a.HID=m.ID And (a.REVIEW_IND != 'D' OR a.REVIEW_IND IS NULL),
countQuery = "select * from AI_DPENTRIES where PAGEID in (select pageid from PAGES where caseid=8960) and (REVIEW_IND != 'D' OR REVIEW_IND IS NULL)",nativeQuery = true)

public Page<AI_DpEntries> getLabAIDpEntries(Pageable pageable);

}

【讨论】:

    猜你喜欢
    • 2021-12-01
    • 2018-03-28
    • 2016-02-03
    • 2019-06-27
    • 2017-11-19
    • 2013-03-22
    • 1970-01-01
    • 1970-01-01
    • 2011-11-25
    相关资源
    最近更新 更多