我正在使用 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。我也无法在这些数据库中创建任何其他表。我没有这样的特权。
最佳答案
您可以将您的 clientID 列表划分为 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);)
}
关于java - spring-data-jpa: ORA-01795: 列表中表达式的最大数量为 1000,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40462110/