【问题标题】:spring-data-jpa: ORA-01795: maximum number of expressions in a list is 1000spring-data-jpa:ORA-01795:列表中的最大表达式数为 1000
【发布时间】:2017-03-20 14:46:09
【问题描述】:

我正在使用 Spring Data JPA。我想从List<String> clientIdList 获取client.id 的交易。问题是我传递了一个非常大的列表,我得到一个 ORA-01795 错误。

@Query(value = "SELECT TransactRepViewModel FROM TransactRepViewModel a WHERE a.clientId IN (?1) AND a.clDate BETWEEN ?2 and ?3", nativeQuery = true)
    List<TransactRepViewModel> findByClientIdList(List<String> clientIdList, Date startDate, Date endDate) throws DataAccessException;

我的客户列表来自另一个数据库通过 oracle 的另一个表,我想不出解决这个问题的方法...

编辑:列表是动态的,因此它可以返回不同数量的 id。我也无法在这些数据库中创建任何其他表。我没有这样的特权。

【问题讨论】:

  • 也许你可以使用associative array

标签: java oracle hibernate spring-data-jpa


【解决方案1】:

您可以将您的客户端 ID 列表划分为 999 个元素的列表,并对数据库进行多次调用。你可以使用Apache Commons ListUtils to do the partitioning

  List<TransactRepViewModel> result = new ArrayList<TransactRepViewModel>();
  final List<List<String>> partitions = ListUtils.partition(clientIdList, 999);
  for (List<String> partition : partitions) {
     result.addAll(yourRepo.findByClientIdList(partition, startDate, endDate);)
  }

【讨论】:

    【解决方案2】:

    您可以将此操作分为两步:

    1. 在表(例如临时表)中插入您的 ID 列表
    2. 将包含大量值的 in 语句更改为在此新(临时)表上具有子选择的 in 语句。

    【讨论】:

    • 不幸的是,我没有权限在这些数据库中创建任何表。
    猜你喜欢
    • 2011-07-12
    • 1970-01-01
    • 1970-01-01
    • 2020-09-28
    • 2018-07-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-24
    相关资源
    最近更新 更多