Hello,
I’m currently running into an issue with a workflow that gets executed every X minutes. Within this workflow I need to call a JavaDelegate class that saves an entity in my database. I’m using JpaRepository to save the entry to my DB. For some reason, the entry is never saved when my workflow is executed, but I am able to successfully save the entry if I were changed this workflow to be manually started.
Here’s what the JavaDelegate code looks like:
@Component
public class SaveEntry implements JavaDelegate {
@Autowired
private Repository repository;
@Override
public void execute(DelegateExecution execution) throws Exception {
// Instantiate obj to be saved
repository.save(obj);
}
}
I’ve found another forum post that’s a little similar to my situation:
I also have a custom config because I’m using two databases for my app. The primary is to store all my application data while the secondary is for Camunda’s process engine. Here’s the custom config file:
@Configuration
@Import(SpringProcessEngineServicesConfiguration.class)
public class WorkflowEngineConfig {
@Value("${spring.datasource.url}")
private String dbSourceUrl;
@Value("${spring.datasource.username}")
private String dbUserName;
@Value("${spring.datasource.password}")
private String dbPassword;
@Value("${spring.datasource.driver-class-name}")
private String dbDriverClassName;
@Bean
@Primary
@ConfigurationProperties(prefix="spring.datasource")
public DataSource primaryDataSource() {
DriverManagerDataSource dataSource = new DriverManagerDataSource();
dataSource.setUrl(dbSourceUrl);
dataSource.setUsername(dbUserName);
dataSource.setPassword(dbPassword);
dataSource.setDriverClassName(dbDriverClassName);
return dataSource;
}
@Bean
public DataSource workflowDataSource() {
DriverManagerDataSource dataSource = new DriverManagerDataSource();
dataSource.setDriverClassName("org.h2.Driver");
dataSource.setUrl("jdbc:h2:mem:process-engine;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE");
dataSource.setUsername("sa");
dataSource.setPassword("");
return dataSource;
}
@Bean
public PlatformTransactionManager transactionManager() {
return new DataSourceTransactionManager(workflowDataSource());
}
@Bean
public SpringProcessEngineConfiguration processEngineConfiguration(
@Value("classpath*:*.bpmn") Resource[] deploymentResources) {
SpringProcessEngineConfiguration config = new SpringProcessEngineConfiguration();
config.setProcessEngineName("workflow-engine");
config.setDataSource(workflowDataSource());
config.setTransactionManager(transactionManager());
config.setDatabaseSchemaUpdate("true");
config.setJobExecutorActivate(true);
config.setDeploymentResources(deploymentResources);
config.setHistory("full");
return config;
}
@Bean
public ProcessEngineFactoryBean engineFactory(SpringProcessEngineConfiguration engineConfiguration) {
ProcessEngineFactoryBean factoryBean = new ProcessEngineFactoryBean();
factoryBean.setProcessEngineConfiguration(engineConfiguration);
return factoryBean;
}
@Bean
public ProcessEngine processEngine(ProcessEngineFactoryBean factoryBean) throws Exception {
return factoryBean.getObject();
}
}
Is this custom config affecting the periodic workflow I’m running? Or is there another reason causing the JavaDelegate file from not saving properly.
Thanks!
