I have a Camunda process engine running inside a spring boot application with a secondary data source. this is the configurations:
@Bean @Primary
public DataSource dataSource(){
SimpleDriverDataSource dataSource = new SimpleDriverDataSource();
dataSource.setDriverClass(org.postgresql.Driver.class);
dataSource.setUrl("jdbc:postgresql://localhost:5432/smq");
// username and password
return dataSource;
}
in other @Configuration class:
@Bean(name="camundaBpmDataSource")
public DataSource camundaDataSource() {
SimpleDriverDataSource dataSource = new SimpleDriverDataSource();
dataSource.setDriverClass(org.postgresql.Driver.class);
dataSource.setUrl("jdbc:postgresql://localhost:5432/camunda");
// username and password
return dataSource;
}
The problem is when I run a java delegate I can’t commit to my primary data source. I don’t receive an error just id does not commit to the data base. code of the java dalegete:
package tn.itserv.smq.application.delegete;
import org.camunda.bpm.engine.delegate.DelegateExecution;
import org.camunda.bpm.engine.delegate.JavaDelegate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import tn.itserv.smq.application.model.Opportunity;
import tn.itserv.smq.application.model.ROaction;
import tn.itserv.smq.application.model.Risk;
import tn.itserv.smq.application.service.OpportunityService;
import tn.itserv.smq.application.service.ROactionService;
import tn.itserv.smq.application.service.RiskService;
@Component
public class CreateNewROAction implements JavaDelegate {
private final ROactionService rOactionService;
private final RiskService riskService;
private final OpportunityService opportunityService;
private Logger logger = LoggerFactory.getLogger(CreateNewROAction.class);
public CreateNewROAction(ROactionService rOactionService, RiskService riskService, OpportunityService opportunityService) {
this.rOactionService = rOactionService;
this.riskService = riskService;
this.opportunityService = opportunityService;
}
@Override @Transactional
public void execute(DelegateExecution delegateExecution) throws Exception {
String processInstanceId = delegateExecution.getProcessInstanceId();
String entityType = delegateExecution.getVariable("entityType").toString();
logger.info("entityType variable value: "+entityType);
if(entityType.equalsIgnoreCase("risk")){
String riskId = delegateExecution.getVariable("riskId").toString();
Risk risk = riskService.findById(Long.parseLong(riskId));
ROaction rOaction = new ROaction();
rOaction.setProcessInstanceId(processInstanceId);
rOaction = saveROAction(rOaction);
logger.info("RO-Action created: "+rOaction);
risk.setAction(rOaction);
risk = updateRisk(risk);
logger.info("risk updated: "+risk);
delegateExecution.setVariable("id", rOaction.getId());
}
else if (entityType.equalsIgnoreCase("opportunity")){
String opportunityId = delegateExecution.getVariable("opportunityId").toString();
Opportunity opportunity = opportunityService.findById(Long.parseLong(opportunityId));
ROaction rOaction = new ROaction();
rOaction.setProcessInstanceId(processInstanceId);
rOaction = saveROAction(rOaction);
opportunity.setAction(rOaction);
opportunity = updateOpportunity(opportunity);
delegateExecution.setVariable("id", rOaction.getId());
}
}
@Transactional(value = "REQUIRES_NEW")
ROaction saveROAction(ROaction rOaction){
return rOactionService.save(rOaction);
}
@Transactional(value = "REQUIRES_NEW")
Risk updateRisk(Risk risk){
return riskService.update(risk, risk.getId());
}
@Transactional(value = "REQUIRES_NEW")
Opportunity updateOpportunity(Opportunity opportunity){
return opportunityService.save(opportunity);
}
}
the result of the logs are:
2019-07-26 14:14:19.292 INFO 8688 --- [nio-8080-exec-6] t.i.s.a.delegete.CreateNewROAction : entityType variable value: risk
2019-07-26 14:14:19.388 INFO 8688 --- [nio-8080-exec-6] t.i.s.a.delegete.CreateNewROAction : RO-Action created: ROaction(id=null, description=null, status=In progress, responsible=null, deadline=null, AchievementDate=null, effectivenessEvaluationDate=null, effectivenessEvaluation=null, processInstanceId=226, createdAt=Fri Jul 26 14:14:19 CET 2019, updatedAt=Fri Jul 26 14:14:19 CET 2019)
2019-07-26 14:14:19.399 INFO 8688 --- [nio-8080-exec-6] t.i.s.a.delegete.CreateNewROAction : risk updated: Risk(id=3, description=some description, probability=3, impact=3, cause=cause, consequence=consequence, action=ROaction(id=null, description=null, status=In progress, responsible=null, deadline=null, AchievementDate=null, effectivenessEvaluationDate=null, effectivenessEvaluation=null, processInstanceId=226, createdAt=Fri Jul 26 14:14:19 CET 2019, updatedAt=Fri Jul 26 14:14:19 CET 2019), processes=[Process(id=5, name=Development and integration, type=Realisation, createdAt=2019-07-26 12:35:35.057282, updatedAt=2019-07-26 12:35:35.057282, pilot=null), Process(id=4, name=Consulting, type=Realisation, createdAt=2019-07-26 12:35:35.057282, updatedAt=2019-07-26 12:35:35.057282, pilot=null), Process(id=3, name=Project management, type=Realisation, createdAt=2019-07-26 12:35:35.057282, updatedAt=2019-07-26 12:35:35.057282, pilot=null)], processInstanceId=201, updatedBy=null, createdAt=2019-07-26 13:56:23.915, updatedAt=2019-07-26 13:56:47.79)
when I call the service from controllers I have no problem to commit the data. The problem occure just in java delegate.
I would be grateful for the help .