我正在使用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。我也无法在这些数据库中创建任何其他表。我没有这样的特权。
答案 0 :(得分:6)
您可以将clientID列表分成999个元素列表,并对DB进行多次调用。您可以使用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);)
}
答案 1 :(得分:1)
您可以分两步拆分此操作: