'Spring-boot Activiti TaskUser causes rollback when perform TaskService.complete

The workflow suspend at a UserTask. After setting the local and process variables, I tried to TaskService.complete(task.getId()). When leave the method, it Rollback. However, there is no information where I can see what actually causes in the exception.

I am using Spring-boot 1.5.10.RELEASE

Below is a snappet of my maven for activiti:

        <dependency>
            <groupId>org.activiti</groupId>
            <artifactId>spring-boot-starter-basic</artifactId>
            <version>5.17.0</version>
        </dependency>
        <dependency>
            <groupId>org.activiti</groupId>
            <artifactId>spring-boot-starter-jpa</artifactId>
            <version>5.17.0</version>
        </dependency>

This is the bpmn file. I have successfully started a new process, that execute fine for the first 2 "stLockCourseMarks" service task and "IsCourseMarkLocked" exclusive gateway. So it suspend at "Moderation" UserTask:

<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:activiti="http://activiti.org/bpmn" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC" xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI" typeLanguage="http://www.w3.org/2001/XMLSchema" expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="http://www.activiti.org/test">
  <process id="cma3" name="Course Marks Approval Workflow v3" isExecutable="true">
    <startEvent id="startevent1" name="Start"></startEvent>
    <serviceTask id="stLockCourseMarks" name="Lock Course Marks" activiti:class="org.bcaa.sms.service.workflow.delegate.LockCourseMarks"></serviceTask>
    <sequenceFlow id="flow1" sourceRef="startevent1" targetRef="stLockCourseMarks"></sequenceFlow>
    <exclusiveGateway id="IsCourseMarkLocked" name="Course Mark Lock Gateway" default="lockFailedFlow"></exclusiveGateway>
    <sequenceFlow id="flow2" sourceRef="stLockCourseMarks" targetRef="IsCourseMarkLocked"></sequenceFlow>
    <userTask id="utModeration" name="Moderation" activiti:assignee="${moderatorId}"></userTask>
    <sequenceFlow id="lockPassedFlow" name="Locked" sourceRef="IsCourseMarkLocked" targetRef="utModeration">
      <conditionExpression xsi:type="tFormalExpression"><![CDATA[${locked.equals("true")}]]></conditionExpression>
    </sequenceFlow>
    <userTask id="utLocalFailDebug" name="Debug Lock Failed" activiti:assignee="${admin}"></userTask>
    <sequenceFlow id="lockFailedFlow" name="Locking failed" sourceRef="IsCourseMarkLocked" targetRef="utLocalFailDebug"></sequenceFlow>
    <sequenceFlow id="relockAfterFailedFlow" name="Relock After Locking Failed Flow" sourceRef="utLocalFailDebug" targetRef="stLockCourseMarks"></sequenceFlow>
    <serviceTask id="stUnlockCourseMarks" name="Unlock Course Marks" activiti:class="org.bcaa.sms.service.workflow.delegate.UnlockCourseMarks"></serviceTask>
    <userTask id="utAdjustMarks" name="Adjust Marks" activiti:assignee="${submitterId}"></userTask>
    <exclusiveGateway id="exclusivegateway1" name="Exclusive Gateway" default="unlockFailedFlow"></exclusiveGateway>
    <sequenceFlow id="flow4" sourceRef="stUnlockCourseMarks" targetRef="exclusivegateway1"></sequenceFlow>
    <sequenceFlow id="flow5" sourceRef="utAdjustMarks" targetRef="stLockCourseMarks"></sequenceFlow>
    <sequenceFlow id="unlockPassedFlow" name="Unlock Passed Flow" sourceRef="exclusivegateway1" targetRef="utAdjustMarks">
      <conditionExpression xsi:type="tFormalExpression"><![CDATA[${locked.equals("false")}]]></conditionExpression>
    </sequenceFlow>
    <userTask id="utDebugUnlockFailed" name="Debug Unlock Failed" activiti:assignee="${admin}"></userTask>
    <sequenceFlow id="unlockFailedFlow" name="Unlock Failed Flow" sourceRef="exclusivegateway1" targetRef="utDebugUnlockFailed"></sequenceFlow>
    <sequenceFlow id="flow7" sourceRef="utDebugUnlockFailed" targetRef="stUnlockCourseMarks"></sequenceFlow>
    <exclusiveGateway id="exclusivegateway2" name="Exclusive Gateway" default="moderationRejectFlow"></exclusiveGateway>
    <sequenceFlow id="flow8" sourceRef="utModeration" targetRef="exclusivegateway2"></sequenceFlow>
    <sequenceFlow id="moderationRejectFlow" name="Reject Flow" sourceRef="exclusivegateway2" targetRef="stUnlockCourseMarks"></sequenceFlow>
    <userTask id="utApproval" name="Approval" activiti:assignee="${approverId}"></userTask>
    <sequenceFlow id="moderationApprovedFlow" name="Approved Flow" sourceRef="exclusivegateway2" targetRef="utApproval">
      <conditionExpression xsi:type="tFormalExpression"><![CDATA[${approvalStatus.equals("APPROVE")}]]></conditionExpression>
    </sequenceFlow>
    <exclusiveGateway id="exclusivegateway3" name="Exclusive Gateway" default="approvalRejectFlow"></exclusiveGateway>
    <sequenceFlow id="flow10" sourceRef="utApproval" targetRef="exclusivegateway3"></sequenceFlow>
    <sequenceFlow id="approvalRejectFlow" name="Reject Flow" sourceRef="exclusivegateway3" targetRef="stUnlockCourseMarks"></sequenceFlow>
    <endEvent id="endevent1" name="End"></endEvent>
    <sequenceFlow id="approvalApprovedFlow" name="Approved Flow" sourceRef="exclusivegateway3" targetRef="endevent1">
      <conditionExpression xsi:type="tFormalExpression"><![CDATA[${approvalStatus.equals("APPROVE")}]]></conditionExpression>
    </sequenceFlow>
    <serviceTask id="stUnlockCourseMarksForInvalidate" name="Unlock Course Marks For Invalidate" activiti:class="org.bcaa.sms.service.workflow.delegate.UnlockCourseMarks"></serviceTask>
    <sequenceFlow id="flow13" sourceRef="exclusivegateway2" targetRef="stUnlockCourseMarksForInvalidate">
      <conditionExpression xsi:type="tFormalExpression"><![CDATA[${approvalStatus.equals("INVALIDATED")}]]></conditionExpression>
    </sequenceFlow>
    <sequenceFlow id="flow14" sourceRef="exclusivegateway3" targetRef="stUnlockCourseMarksForInvalidate">
      <conditionExpression xsi:type="tFormalExpression"><![CDATA[${approvalStatus.equals("INVALIDATED")}]]></conditionExpression>
    </sequenceFlow>
    <endEvent id="terminateendevent1" name="TerminateEndEvent">
      <terminateEventDefinition></terminateEventDefinition>
    </endEvent>
    <sequenceFlow id="flow15" sourceRef="stUnlockCourseMarksForInvalidate" targetRef="terminateendevent1"></sequenceFlow>
    <sequenceFlow id="flow16" sourceRef="IsCourseMarkLocked" targetRef="stUnlockCourseMarksForInvalidate">
      <conditionExpression xsi:type="tFormalExpression"><![CDATA[${approvalStatus.equals("INVALIDATED")}]]></conditionExpression>
    </sequenceFlow>
  </process>
  <bpmndi:BPMNDiagram id="BPMNDiagram_cma3">
    <bpmndi:BPMNPlane bpmnElement="cma3" id="BPMNPlane_cma3">
      <bpmndi:BPMNShape bpmnElement="startevent1" id="BPMNShape_startevent1">
        <omgdc:Bounds height="35.0" width="35.0" x="41.0" y="206.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="stLockCourseMarks" id="BPMNShape_stLockCourseMarks">
        <omgdc:Bounds height="61.0" width="105.0" x="160.0" y="193.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="IsCourseMarkLocked" id="BPMNShape_IsCourseMarkLocked">
        <omgdc:Bounds height="40.0" width="40.0" x="340.0" y="203.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="utModeration" id="BPMNShape_utModeration">
        <omgdc:Bounds height="55.0" width="105.0" x="432.0" y="196.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="utLocalFailDebug" id="BPMNShape_utLocalFailDebug">
        <omgdc:Bounds height="71.0" width="105.0" x="308.0" y="30.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="stUnlockCourseMarks" id="BPMNShape_stUnlockCourseMarks">
        <omgdc:Bounds height="71.0" width="105.0" x="536.0" y="312.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="utAdjustMarks" id="BPMNShape_utAdjustMarks">
        <omgdc:Bounds height="55.0" width="105.0" x="160.0" y="320.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="exclusivegateway1" id="BPMNShape_exclusivegateway1">
        <omgdc:Bounds height="40.0" width="40.0" x="340.0" y="327.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="utDebugUnlockFailed" id="BPMNShape_utDebugUnlockFailed">
        <omgdc:Bounds height="65.0" width="105.0" x="308.0" y="450.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="exclusivegateway2" id="BPMNShape_exclusivegateway2">
        <omgdc:Bounds height="40.0" width="40.0" x="568.0" y="203.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="utApproval" id="BPMNShape_utApproval">
        <omgdc:Bounds height="55.0" width="105.0" x="683.0" y="196.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="exclusivegateway3" id="BPMNShape_exclusivegateway3">
        <omgdc:Bounds height="40.0" width="40.0" x="819.0" y="203.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="endevent1" id="BPMNShape_endevent1">
        <omgdc:Bounds height="35.0" width="35.0" x="1000.0" y="206.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="stUnlockCourseMarksForInvalidate" id="BPMNShape_stUnlockCourseMarksForInvalidate">
        <omgdc:Bounds height="71.0" width="105.0" x="787.0" y="10.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="terminateendevent1" id="BPMNShape_terminateendevent1">
        <omgdc:Bounds height="35.0" width="35.0" x="1000.0" y="28.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNEdge bpmnElement="flow1" id="BPMNEdge_flow1">
        <omgdi:waypoint x="76.0" y="223.0"></omgdi:waypoint>
        <omgdi:waypoint x="160.0" y="223.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="flow2" id="BPMNEdge_flow2">
        <omgdi:waypoint x="265.0" y="223.0"></omgdi:waypoint>
        <omgdi:waypoint x="340.0" y="223.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="lockPassedFlow" id="BPMNEdge_lockPassedFlow">
        <omgdi:waypoint x="380.0" y="223.0"></omgdi:waypoint>
        <omgdi:waypoint x="432.0" y="223.0"></omgdi:waypoint>
        <bpmndi:BPMNLabel>
          <omgdc:Bounds height="16.0" width="42.0" x="379.0" y="223.0"></omgdc:Bounds>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="lockFailedFlow" id="BPMNEdge_lockFailedFlow">
        <omgdi:waypoint x="360.0" y="203.0"></omgdi:waypoint>
        <omgdi:waypoint x="360.0" y="101.0"></omgdi:waypoint>
        <bpmndi:BPMNLabel>
          <omgdc:Bounds height="48.0" width="66.0" x="360.0" y="182.0"></omgdc:Bounds>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="relockAfterFailedFlow" id="BPMNEdge_relockAfterFailedFlow">
        <omgdi:waypoint x="308.0" y="65.0"></omgdi:waypoint>
        <omgdi:waypoint x="212.0" y="65.0"></omgdi:waypoint>
        <omgdi:waypoint x="212.0" y="193.0"></omgdi:waypoint>
        <bpmndi:BPMNLabel>
          <omgdc:Bounds height="48.0" width="100.0" x="218.0" y="68.0"></omgdc:Bounds>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="flow4" id="BPMNEdge_flow4">
        <omgdi:waypoint x="536.0" y="347.0"></omgdi:waypoint>
        <omgdi:waypoint x="380.0" y="347.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="flow5" id="BPMNEdge_flow5">
        <omgdi:waypoint x="212.0" y="320.0"></omgdi:waypoint>
        <omgdi:waypoint x="212.0" y="254.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="unlockPassedFlow" id="BPMNEdge_unlockPassedFlow">
        <omgdi:waypoint x="340.0" y="347.0"></omgdi:waypoint>
        <omgdi:waypoint x="265.0" y="347.0"></omgdi:waypoint>
        <bpmndi:BPMNLabel>
          <omgdc:Bounds height="48.0" width="100.0" x="265.0" y="352.0"></omgdc:Bounds>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="unlockFailedFlow" id="BPMNEdge_unlockFailedFlow">
        <omgdi:waypoint x="360.0" y="367.0"></omgdi:waypoint>
        <omgdi:waypoint x="360.0" y="450.0"></omgdi:waypoint>
        <bpmndi:BPMNLabel>
          <omgdc:Bounds height="48.0" width="90.0" x="365.0" y="381.0"></omgdc:Bounds>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="flow7" id="BPMNEdge_flow7">
        <omgdi:waypoint x="413.0" y="482.0"></omgdi:waypoint>
        <omgdi:waypoint x="588.0" y="482.0"></omgdi:waypoint>
        <omgdi:waypoint x="588.0" y="382.0"></omgdi:waypoint>
        <omgdi:waypoint x="641.0" y="347.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="flow8" id="BPMNEdge_flow8">
        <omgdi:waypoint x="537.0" y="223.0"></omgdi:waypoint>
        <omgdi:waypoint x="568.0" y="223.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="moderationRejectFlow" id="BPMNEdge_moderationRejectFlow">
        <omgdi:waypoint x="588.0" y="243.0"></omgdi:waypoint>
        <omgdi:waypoint x="588.0" y="312.0"></omgdi:waypoint>
        <bpmndi:BPMNLabel>
          <omgdc:Bounds height="48.0" width="57.0" x="590.0" y="265.0"></omgdc:Bounds>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="moderationApprovedFlow" id="BPMNEdge_moderationApprovedFlow">
        <omgdi:waypoint x="608.0" y="223.0"></omgdi:waypoint>
        <omgdi:waypoint x="683.0" y="223.0"></omgdi:waypoint>
        <bpmndi:BPMNLabel>
          <omgdc:Bounds height="16.0" width="84.0" x="599.0" y="229.0"></omgdc:Bounds>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="flow10" id="BPMNEdge_flow10">
        <omgdi:waypoint x="788.0" y="223.0"></omgdi:waypoint>
        <omgdi:waypoint x="819.0" y="223.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="approvalRejectFlow" id="BPMNEdge_approvalRejectFlow">
        <omgdi:waypoint x="839.0" y="243.0"></omgdi:waypoint>
        <omgdi:waypoint x="841.0" y="347.0"></omgdi:waypoint>
        <omgdi:waypoint x="641.0" y="347.0"></omgdi:waypoint>
        <bpmndi:BPMNLabel>
          <omgdc:Bounds height="48.0" width="57.0" x="749.0" y="319.0"></omgdc:Bounds>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="approvalApprovedFlow" id="BPMNEdge_approvalApprovedFlow">
        <omgdi:waypoint x="859.0" y="223.0"></omgdi:waypoint>
        <omgdi:waypoint x="1000.0" y="223.0"></omgdi:waypoint>
        <bpmndi:BPMNLabel>
          <omgdc:Bounds height="16.0" width="84.0" x="859.0" y="223.0"></omgdc:Bounds>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="flow13" id="BPMNEdge_flow13">
        <omgdi:waypoint x="588.0" y="203.0"></omgdi:waypoint>
        <omgdi:waypoint x="588.0" y="47.0"></omgdi:waypoint>
        <omgdi:waypoint x="787.0" y="45.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="flow14" id="BPMNEdge_flow14">
        <omgdi:waypoint x="839.0" y="203.0"></omgdi:waypoint>
        <omgdi:waypoint x="839.0" y="81.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="flow15" id="BPMNEdge_flow15">
        <omgdi:waypoint x="892.0" y="45.0"></omgdi:waypoint>
        <omgdi:waypoint x="1000.0" y="45.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="flow16" id="BPMNEdge_flow16">
        <omgdi:waypoint x="360.0" y="203.0"></omgdi:waypoint>
        <omgdi:waypoint x="360.0" y="149.0"></omgdi:waypoint>
        <omgdi:waypoint x="589.0" y="149.0"></omgdi:waypoint>
        <omgdi:waypoint x="589.0" y="45.0"></omgdi:waypoint>
        <omgdi:waypoint x="787.0" y="45.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
    </bpmndi:BPMNPlane>
  </bpmndi:BPMNDiagram>
</definitions>

Below is the method that tries to complete the utModeration UserTask. However, i encounter rollback here.

@Transactional(readOnly = false, propagation=Propagation.REQUIRED)
    public List<String> approveCourseMarks(CourseMarksApprovalDto dto, AppUser auser) 
    throws SmsException {
        
        if (dto == null) throw new SmsException("No approval received","Invalid Approval");
        List<String> errors = new ArrayList<String>();
        
        if (dto == null || dto.getTaskId() == null) throw new SmsException("No task information received. Unable to proceed.","Invalid Task");
        System.out.println("=== dto="+dto);
        Task task = wfTaskService.createTaskQuery()
                        .taskId(dto.getTaskId())
                        .active()
                        .singleResult();
        
        if (task == null) {
            errors.add("Course " + dto.getCourse().getFullname() 
                                 + " workflow task is not available to processing. It may already been approved/rejected.");
        }

            Map<String, Object> localVars = new HashMap<String,Object>();
            
            localVars.put(CourseMarksWorkflowService.VAR_REMARKS, dto.getRemarks());
            localVars.put(CourseMarksWorkflowService.CONDITION_APPROVAL_STATUS, dto.getApprovalStatus());
            localVars.put(CourseMarksWorkflowService.VAR_ACTUAL_AO_ID, auser.getId());
            wfTaskService.setVariablesLocal(task.getId(), localVars);
            wfRuntimeService.setVariable(task.getProcessInstanceId(), CourseMarksWorkflowService.CONDITION_APPROVAL_STATUS, dto.getApprovalStatus());
            
            wfTaskService.complete(task.getId());

        return errors;
    }

Below is the exception i encounter:

2019-12-06 21:35:10.328  INFO 24076 --- [nio-8090-exec-3] o.a.e.i.b.d.BpmnDeployer                 : Processing resource D:\project\smsg2\application\sms4\target\classes\processes\Cma5.cma3.png
    2019-12-06 21:35:10.328  INFO 24076 --- [nio-8090-exec-3] o.a.e.i.b.d.BpmnDeployer                 : Processing resource D:\project\smsg2\application\sms4\target\classes\processes\Cma5.bpmn20.xml
    2019-12-06 21:35:22.242 DEBUG 24076 --- [nio-8090-exec-3] .m.m.a.ExceptionHandlerExceptionResolver : Resolving exception from handler [public org.springframework.http.ResponseEntity<java.util.List<java.lang.String>> org.bcaa.sms.controller_hal.result.MarksApprovalHalController.approveCourseMarks(org.bcaa.sms.dto.CourseMarksApprovalDto,java.security.Principal) throws org.bcaa.sms.exception.SmsException]: org.springframework.transaction.TransactionSystemException: Could not commit JPA transaction; nested exception is javax.persistence.RollbackException: Transaction marked as rollbackOnly
    2019-12-06 21:35:22.242 DEBUG 24076 --- [nio-8090-exec-3] .m.m.a.ExceptionHandlerExceptionResolver : Resolving exception from handler [public org.springframework.http.ResponseEntity<java.util.List<java.lang.String>> org.bcaa.sms.controller_hal.result.MarksApprovalHalController.approveCourseMarks(org.bcaa.sms.dto.CourseMarksApprovalDto,java.security.Principal) throws org.bcaa.sms.exception.SmsException]: org.springframework.transaction.TransactionSystemException: Could not commit JPA transaction; nested exception is javax.persistence.RollbackException: Transaction marked as rollbackOnly
    2019-12-06 21:35:22.242 DEBUG 24076 --- [nio-8090-exec-3] .w.s.m.a.ResponseStatusExceptionResolver : Resolving exception from handler [public org.springframework.http.ResponseEntity<java.util.List<java.lang.String>> org.bcaa.sms.controller_hal.result.MarksApprovalHalController.approveCourseMarks(org.bcaa.sms.dto.CourseMarksApprovalDto,java.security.Principal) throws org.bcaa.sms.exception.SmsException]: org.springframework.transaction.TransactionSystemException: Could not commit JPA transaction; nested exception is javax.persistence.RollbackException: Transaction marked as rollbackOnly
    2019-12-06 21:35:22.243 DEBUG 24076 --- [nio-8090-exec-3] .w.s.m.s.DefaultHandlerExceptionResolver : Resolving exception from handler [public org.springframework.http.ResponseEntity<java.util.List<java.lang.String>> org.bcaa.sms.controller_hal.result.MarksApprovalHalController.approveCourseMarks(org.bcaa.sms.dto.CourseMarksApprovalDto,java.security.Principal) throws org.bcaa.sms.exception.SmsException]: org.springframework.transaction.TransactionSystemException: Could not commit JPA transaction; nested exception is javax.persistence.RollbackException: Transaction marked as rollbackOnly
    2019-12-06 21:35:22.243 DEBUG 24076 --- [nio-8090-exec-3] o.s.w.s.DispatcherServlet                : Could not complete request
    
    org.springframework.transaction.TransactionSystemException: Could not commit JPA transaction; nested exception is javax.persistence.RollbackException: Transaction marked as rollbackOnly
        at org.springframework.orm.jpa.JpaTransactionManager.doCommit(JpaTransactionManager.java:526) ~[spring-orm-4.3.14.RELEASE.jar:4.3.14.RELEASE]
        at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:761) ~[spring-tx-4.3.14.RELEASE.jar:4.3.14.RELEASE]
        at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:730) ~[spring-tx-4.3.14.RELEASE.jar:4.3.14.RELEASE]
        at org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:518) ~[spring-tx-4.3.14.RELEASE.jar:4.3.14.RELEASE]
        at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:292) ~[spring-tx-4.3.14.RELEASE.jar:4.3.14.RELEASE]
        at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96) ~[spring-tx-4.3.14.RELEASE.jar:4.3.14.RELEASE]
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.3.14.RELEASE.jar:4.3.14.RELEASE]
        at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:673) ~[spring-aop-4.3.14.RELEASE.jar:4.3.14.RELEASE]
        at org.bcaa.sms.service.result.MarksApprovalService$$EnhancerBySpringCGLIB$$23b0f39d.approveCourseMarks(<generated>) ~[classes/:?]
        at org.bcaa.sms.controller_hal.result.MarksApprovalHalController.approveCourseMarks(MarksApprovalHalController.java:113) ~[classes/:?]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_172]
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_172]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_172]
        at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_172]
        at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:205) ~[spring-web-4.3.14.RELEASE.jar:4.3.14.RELEASE]
        at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:133) ~[spring-web-4.3.14.RELEASE.jar:4.3.14.RELEASE]
        at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:97) ~[spring-webmvc-4.3.14.RELEASE.jar:4.3.14.RELEASE]
        at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:827) ~[spring-webmvc-4.3.14.RELEASE.jar:4.3.14.RELEASE]
        at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:738) ~[spring-webmvc-4.3.14.RELEASE.jar:4.3.14.RELEASE]
        at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85) ~[spring-webmvc-4.3.14.RELEASE.jar:4.3.14.RELEASE]
        at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:967) ~[spring-webmvc-4.3.14.RELEASE.jar:4.3.14.RELEASE]
        at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:901) ~[spring-webmvc-4.3.14.RELEASE.jar:4.3.14.RELEASE]
        at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970) [spring-webmvc-4.3.14.RELEASE.jar:4.3.14.RELEASE]
        at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:872) [spring-webmvc-4.3.14.RELEASE.jar:4.3.14.RELEASE]
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:661) [tomcat-embed-core-8.5.27.jar:8.5.27]
        at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846) [spring-webmvc-4.3.14.RELEASE.jar:4.3.14.RELEASE]
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:742) [tomcat-embed-core-8.5.27.jar:8.5.27]
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231) [tomcat-embed-core-8.5.27.jar:8.5.27]
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) [tomcat-embed-core-8.5.27.jar:8.5.27]
        at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) [tomcat-embed-websocket-8.5.27.jar:8.5.27]
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) [tomcat-embed-core-8.5.27.jar:8.5.27]
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) [tomcat-embed-core-8.5.27.jar:8.5.27]
        at org.springframework.security.web.authentication.www.BasicAuthenticationFilter.doFilterInternal(BasicAuthenticationFilter.java:215) [spring-security-web-4.2.4.RELEASE.jar:4.2.4.RELEASE]
        at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) [spring-web-4.3.14.RELEASE.jar:4.3.14.RELEASE]
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) [tomcat-embed-core-8.5.27.jar:8.5.27]
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) [tomcat-embed-core-8.5.27.jar:8.5.27]
        at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:317) [spring-security-web-4.2.4.RELEASE.jar:4.2.4.RELEASE]
        at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:127) [spring-security-web-4.2.4.RELEASE.jar:4.2.4.RELEASE]
        at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:91) [spring-security-web-4.2.4.RELEASE.jar:4.2.4.RELEASE]
        at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331) [spring-security-web-4.2.4.RELEASE.jar:4.2.4.RELEASE]
        at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:114) [spring-security-web-4.2.4.RELEASE.jar:4.2.4.RELEASE]
        at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331) [spring-security-web-4.2.4.RELEASE.jar:4.2.4.RELEASE]
        at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:137) [spring-security-web-4.2.4.RELEASE.jar:4.2.4.RELEASE]
        at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331) [spring-security-web-4.2.4.RELEASE.jar:4.2.4.RELEASE]
        at org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:111) [spring-security-web-4.2.4.RELEASE.jar:4.2.4.RELEASE]
        at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331) [spring-security-web-4.2.4.RELEASE.jar:4.2.4.RELEASE]
        at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:170) [spring-security-web-4.2.4.RELEASE.jar:4.2.4.RELEASE]
        at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331) [spring-security-web-4.2.4.RELEASE.jar:4.2.4.RELEASE]
        at org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:63) [spring-security-web-4.2.4.RELEASE.jar:4.2.4.RELEASE]
        at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331) [spring-security-web-4.2.4.RELEASE.jar:4.2.4.RELEASE]
        ... 105 more
    
    2019-12-06 21:35:22.260 ERROR 24076 --- [nio-8090-exec-3] o.a.c.c.C.[.[.[.[dispatcherServlet]      : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.transaction.TransactionSystemException: Could not commit JPA transaction; nested exception is javax.persistence.RollbackException: Transaction marked as rollbackOnly] with root cause
    
    javax.persistence.RollbackException: Transaction marked as rollbackOnly
        at org.hibernate.jpa.internal.TransactionImpl.commit(TransactionImpl.java:58) ~[hibernate-entitymanager-5.0.12.Final.jar:5.0.12.Final]
        at org.springframework.orm.jpa.JpaTransactionManager.doCommit(JpaTransactionManager.java:517) ~[spring-orm-4.3.14.RELEASE.jar:4.3.14.RELEASE]
 

What could be cause of the issue? Thanks.



Solution 1:[1]

Managed to solved it; require to change the transaction progration from REQUIRES to REQUIRES_NEW. That is the annotation of the method change to this:

@Transactional(readOnly = false, propagation=Propagation.REQUIRES_NEW)

Do not know exactly why this solve the problem though. If anyone know the reason, will be interested to know.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 bmw34