Uploaded image for project: 'Olingo'
  1. Olingo
  2. OLINGO-1464

Batch with multiple change sets does not work,

    XMLWordPrintableJSON

Details

    • Question
    • Status: Open
    • Major
    • Resolution: Unresolved
    • V2 2.0.11
    • None
    • odata2-jpa
    • None

    Description

      You can see a full report regarding the olingo jpa problem with batches that have more than one changeset. 

      https://github.com/jpenninkhof/odata-boilerplate/issues/1

      As soon as you have multiple change sets you will see the following error:

      <?xml version='1.0' encoding='UTF-8'?><error xmlns="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">    <code/>    <message xml:lang="en">Error on processing request content:Cannot begin Transaction on closed Session/EntityManager</message></error>
      

      The problems is coming from 2 lines that I commented them out as following:

      @Override
        public BatchResponsePart executeChangeSet(final BatchHandler handler, final List<ODataRequest> requests)
            throws ODataException {
          List<ODataResponse> responses = new ArrayList<ODataResponse>();
          try {
            //oDataJPAContext.getODataJPATransaction().begin();
      
            for (ODataRequest request : requests) {
              oDataJPAContext.setODataContext(getContext());
              ODataResponse response = handler.handleRequest(request);
              if (response.getStatus().getStatusCode() >= HttpStatusCodes.BAD_REQUEST.getStatusCode()) {
                // Roll Back
                oDataJPAContext.getODataJPATransaction().rollback();
                List<ODataResponse> errorResponses = new ArrayList<ODataResponse>(1);
                errorResponses.add(response);
                return BatchResponsePart.responses(errorResponses).changeSet(false).build();
              }
              responses.add(response);
            }
            //oDataJPAContext.getODataJPATransaction().commit();
            return BatchResponsePart.responses(responses).changeSet(true).build();
          } catch (Exception e) {
            throw new ODataException("Error on processing request content:" + e.getMessage(), e);
          } finally {
            close(true);
          }
        }

       

      It does not need to `commit` after each changeset!

      Attachments

        Activity

          People

            Unassigned Unassigned
            mjz Mahdi Ansari
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated: