spring-data-jpa:ORA-01795:列表中的最大表达式数为1000

Den*_* M. 6 java oracle hibernate spring-data-jpa

我正在使用Spring Data JPA.我想从a获取client.id的事务List<String> clientIdList.问题是我传递了一个非常大的列表,我收到了一个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;
Run Code Online (Sandbox Code Playgroud)

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

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

Rob*_*roj 8

您可以将clientID列表分成999个元素列表,并对DB进行多次调用.您可以使用Apache Commons ListUtils进行分区:

  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);)
  }
Run Code Online (Sandbox Code Playgroud)