@Override
    public Operation update(Operation src) throws TransferServiceException {
        Transfer transfer = findByOperationId(src.getId());
        Operation result = null;
        try {
            if (src.getOperationType() == OperationType.transferTo) {
                result = operationService.update(src);
                Operation from = transfer.getFrom();
                manager.detach(from);
                from.setCost(src.getCost());
                operationService.update(from);
            }
            if (src.getOperationType() == OperationType.transferFrom) {
                result = operationService.update(src);
                Operation to = transfer.getTo();
                manager.detach(to);
                to.setCost(src.getCost());
                operationService.update(to);
            }
        } catch (OperationServiceException e) {
            throw new TransferServiceException(e.getMessage());
        }
        if (result == null) {
            throw new TransferServiceException(INVALID_OPERATION_TYPE);
        }
        transfer.setAmount(src.getCost());
        manager.merge(transfer);
        manager.flush();
        return result;
    }