oracle ORA-01002:批量提取记录时,提取顺序不正确

xe55xuns  于 2023-04-29  发布在  Oracle
关注(0)|答案(1)|浏览(422)

使用Hibernate 5。4.24.Final与Oracle数据库(19 c),当试图批量提取记录,我得到以下错误后检索60 k记录。有人能建议如何解决吗?
错误:
18:54:10,224 WARN(警告)hibernate.engine.jdbc.spi.SqlExceptionHelper](default task-4)SQL错误:1002,SQLState:24000
18:54:10,224 ERROR [org.hibernate.engine.SqlExceptionHelper](默认任务-4)ORA-01002:不按顺序取出
查询:

List<Object[]> objectInMemList = new ArrayList<>();
final BigDecimal count = (BigDecimal) entityManager.createNativeQuery("SELECT COUNT (RP.id) AS count FROM TABLE1 RP INNER JOIN TABLE2 CS ON RP.ID = ?1 AND RP.CUSTOMER_ID = CS.ID ORDER BY RP.CREATION_DATE").setParameter(1, 123456).getSingleResult();

int numberOfRequests = count.intValue() < 20000 ? 1 : (int)Math.ceil(count.intValue() / 20000);

for(int req = 0; req < numberOfRequests; req++) {
    final Query query = entityManager.createNativeQuery("SELECT RP.ID AS id, RP.field1, CS.field2 AS field2, CS.field3 AS field3, RP.field2 AS rpfield2 FROM TABLE1 RP INNER JOIN TABLE2 CS ON RP.Id = ?1 AND RP.CUSTOMER_ID = CS.ID")
.setFirstResult(req*20000).setMaxResults(20000).setHint(QueryHints.READ_ONLY, true).setParameter(1, 123456);
    final List<Object[]> resultList = query.getResultList();
    objectInMemList.addAll(resultList);
}

批量查询原因:检索数百万条记录并避免超时
我在网上检查了这个错误,但它都与INSERT/UPDATE或SQL过程有关。当我进行选择查询时,我有点困惑这个错误是从哪里发生的,因为整个请求都发生在一个线程中?

nszi6y05

nszi6y051#

我发现问题了。由于某种原因,当事务超时时,我会得到此错误。增加事务超时时间解决了此问题

相关问题