Details
-
Question
-
Status: Open
-
Major
-
Resolution: Unresolved
-
V2 2.0.11
-
None
-
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!