2013-06-06 3 views
0

안녕하세요 저는 봄에 서비스를 제공 할 것입니다. 봄베이 메소드 (A 메소드)는 두 개의 작업을 수행합니다. 첫 번째 방법은 하이버 네이트 DAO 메소드 (B 메소드)를 통해 데이터베이스에 데이터를 저장합니다. -activiti 워크 플로 (C 방법) 다음 단계로 이동합니다. 이제 스프링 트랜잭션 관리자를 사용하고 있습니다. 그리고 아래의 트랜잭션을 사용하고 있습니다. 여기 내 질문은 워크 플로 메서드에서 일부 예외가 발견되면 데이터베이스 변경 내용을 되돌릴 수 없습니다. ..여러 트랜잭션을 사용하는 스프링 서비스 방법

@Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = Exception.class) 
@Override 
public WorkflowResponseBO saveDraft(PETIncidentBO pETIncident) throws DDMApplicationException { 
Investigation investigation = savePETIncident(pETIncident); 
WorkflowResponseBO workflowResponse = null; 
if (pETIncident.getWorkflowId() == null) { 
    workflowResponse = initiateWorkflow(pETIncident, investigation); 
} 
return workflowResponse; 
} 

@Transactional(propagation = Propagation.REQUIRES_NEW, readOnly = false, rollbackFor = Exception.class) 
private Investigation savePETIncident(PETIncidentBO pETIncident) throws DDMApplicationException { 
LOGGER.info("Entered Method :: savePETIncident"); 
Investigation investigation = null; 
try { 
    if (pETIncident.getWorkflowId() != null) { 
    investigation = investigationDao.findInvestigationByWorkflowId(pETIncident.getWorkflowId()); 
    } 

    // Incident Data 
    Incident incident = getIncidentDetails(investigation, pETIncident); 

    // Investigation Data 
    if (investigation == null) { 
    investigation = new Investigation(); 
    investigation.setInvestigatedInvolvedPerson(getIncidentInvolvedPersonDetails(incident, pETIncident)); 
    MasterLookup allegedViolationType = null; 
    allegedViolationType = masterLookupDao.findMasterLookupByShortDesc(DDMConstants.PROBATIONARY_TERMINATION_LOOKUP); 
    investigation.setAllegedViolationType(allegedViolationType); 
    CollectiveBargainingAgreement collectiveBargainingAgreement = null; 
    collectiveBargainingAgreement = collectiveBargainingAgreementDao.findCollectiveBargainingAgreementbyId(pETIncident.getCba().getCollectiveBargainingAgreementId()); 
    investigation.setCollectiveBargainingAgreement(collectiveBargainingAgreement); 
    investigation.setIncident(incident); 
    } 
    // updating the address and rehire status of the involved person 
    investigation = updateInvesigationInvolvedPersonDetails(investigation, pETIncident); 

    InvestigationUnstructuredContent content = getInvestigationUnstructuredContentDetails(investigation, pETIncident); 

    content = getInvestigationUnstContentDeliveryDetails(pETIncident, content, investigation.getInvestigatedInvolvedPerson().getPerson()); 

    investigation.getInvestigationUnstConts().add(content); 

    investigation = getInvestigationAssignedPersonDetails(investigation, incident, pETIncident); 

    if (investigation.getInvestigationId() == null) { 
    investigationDao.createinvestigation(investigation); 
    } else { 
    investigationDao.updateinvestigation(investigation); 
    } 

} catch (DDMDBException de) { 
    LOGGER.error(de); 
    DDMServicesExceptionHandler.handleException(de); 
} catch (DDMApplicationException da) { 
    LOGGER.error(da); 
    DDMServicesExceptionHandler.handleException(da); 
} catch (Exception e) { 
    LOGGER.error(e); 
    DDMServicesExceptionHandler.handleException(e); 
} 
LOGGER.info("Exited Method :: savePETIncident"); 
return investigation; 
} 
@Transactional(propagation = Propagation.REQUIRES_NEW, readOnly = false, rollbackFor = Exception.class) 
private WorkflowResponseBO initiateWorkflow(PETIncidentBO pETIncident, Investigation investigation) throws DDMApplicationException { 
// updating the workflow id in the investigation table 
WorkflowResponseBO workflowResponse = null; 
PETWorkflowDetailsBO petWorkflowDetails = new PETWorkflowDetailsBO(); 
petWorkflowDetails.setCbaId(investigation.getCollectiveBargainingAgreement().getCollectiveBargainingAgreementId().toString()); 
petWorkflowDetails.setInitiatorEmployeeId(pETIncident.getIncidentCreatorEmployeeId()); 
petWorkflowDetails.setInvovledPersonEmployeeId(pETIncident.getInvolvedPersonDeliveryDetails().getPerson().getEmployeeId()); 
petWorkflowDetails.setReasonForTermination(pETIncident.getReasonForTermination().getLookupShortDesc()); 
petWorkflowDetails.setTerminationDate(DdmDateUtils.dateToString(pETIncident.getTerminationDate(), DDMConstants.DISPLAY_DATE_FORMAT)); 
workflowResponse = petWorkflowService.reportProbationaryEmployeeTermination(petWorkflowDetails); 
investigation.setWorkflowId(workflowResponse.getProcessId()); 
try { 
    investigationDao.updateinvestigation(investigation); 
} catch (DDMDBException e) { 
    LOGGER.error("Error while updating investigation table"); 
    DDMServicesExceptionHandler.handleException(e); 

} 
if (workflowResponse == null) { 
    workflowResponse = new WorkflowResponseBO(); 
    workflowResponse.setProcessId(pETIncident.getWorkflowId()); 
    workflowResponse.setTaskId(pETIncident.getTaskId()); 
} 
return workflowResponse; 
} 

답변

0

클래스 기반 프록시가 클래스를로드하고 트랜잭션 내에서 saveDraft 메소드를 래핑 할 때. 이 클래스의 메소드에 대한 추가 호출을 처리 할 때 스프링이 루프에서 벗어 났으므로 중첩 된 트랜잭션을 만들지 않습니다.

자체 호출이 트랜잭션으로 랩핑 될 것으로 예상되는 경우 AspectJ 모드의 사용을 고려하십시오. 이 경우 처음에는 프록시가 없습니다. 대신, @Transactional을 모든 종류의 메소드에서 런타임 동작으로 바꾸기 위해 대상 클래스가 만들어집니다 (즉, 바이트 코드가 수정됩니다).

프로그래밍 방식의 트랜잭션을 사용할 수도 있습니다.