I have a long for loop (5k loops) each loop make an operation to database through
if(!runnedPedidosToBulkOrCronjobClientesService.checkIsRunned(pedido.getId())){
return;
}
The checkIsRunned
method is that one will look up over the database it’s:
public Boolean checkIsRunned(Integer id_pedido){
return runnedPedidosToBulkOrCronjobClientesRepository.findById(id_pedido).isEmpty();
}
Where runnedPedidosToBulkOrCronjobClientesRepository
is a injected instance from a JbaRepository
@Repository
public interface RunnedPedidosToBulkOrCronjobClientesRepository extends JpaRepository<RunnedPedidosToBulkOrCronjobClientesEntidade,Integer> {
}
This for loop is triggered by a HTTP request, and it returns no exception in each loop, but if internet goes down and it’s restored, even after it’s restores each for loop will throw
Could not open JPA EntityManager for transaction
The part of for loop which gets me this exception is:
if(!runnedPedidosToBulkOrCronjobClientesService.checkIsRunned(pedido.getId())){
return;
}
I suspect the repository gets bugged state after internet is restored, probably instantiate this repository would resolve the problem but I still would like to use dependency injection, I need a solution can hold it without reseting for loop in a internet loss.