I am trying to retry after optimistic lock failed, but JPA close the connection and didn't reconnect it.
public String updateTnx(Integer id, String txt) {
        Tnx tnx = tnxRepository.findById(id);
        //record update by other process
        tnx.txt = txt;
        tnxRepository.save(tnx);
        return tnx.toJson();
    }
1:In this case ObjectOptimisticLockingFailureException is throw because another process have update the version column.
@Retryable(value = {ObjectOptimisticLockingFailureException.class})
    public String updateTnx(Integer id, String txt) {
        Tnx tnx = tnxRepository.findById(id);
        tnx.txt = txt;
        tnxRepository.save(tnx);
        return tnx.toJson();
    }
2:So I add retryable to the method, but I have got StatementIsClosedException.
public String updateTnx(Integer id, String txt) {
        try {
            Tnx tnx = tnxRepository.findById(id);
            tnx.txt = txt;
            tnxRepository.save(tnx);
            return tnx.toJson();
        } catch (ObjectOptimisticLockingFailureException exp) {
            Tnx tnx = tnxRepository.findById(id);
            tnx.txt = txt;
            Ttt ttt = new Ttt();
            tttRepository.save(ttt);
            tnxRepository.save(tnx);
            return tnx.toJson();
        }
    }
3: I can add StatementIsClosedException to retryable that works, but the weird thing is if I put another table to update before target one, which also works.
My question is, are JPA caching last prepared statement which cause StatementIsClosedException ?