Creating a Custom Batch fails due to missing start time

I’m migrating from Camunda 7.16.8 to 7.18.1, but I’m having a problem with a failing unit test:

Caused by: org.apache.ibatis.executor.BatchExecutorException: org.camunda.bpm.engine.impl.batch.history.HistoricBatchEntity.insertHistoricBatch (batch index #6) failed. 5 prior sub executor(s) completed successfully, but will be rolled back. Cause: org.h2.jdbc.JdbcBatchUpdateException: NULL nicht zulässig für Feld "START_TIME_"
NULL not allowed for column "START_TIME_"; SQL statement:
insert into ACT_HI_BATCH
    (
      ID_,
      TYPE_,
      TOTAL_JOBS_,
      JOBS_PER_SEED_,
      INVOCATIONS_PER_JOB_,
      SEED_JOB_DEF_ID_,
      MONITOR_JOB_DEF_ID_,
      BATCH_JOB_DEF_ID_,
      TENANT_ID_,
      CREATE_USER_ID_,
      START_TIME_,
      END_TIME_,
      REMOVAL_TIME_
    )
    values
    (
      ?,
      ?,
      ?,
      ?,
      ?,
      ?,
      ?,
      ?,
      ?,
      ?,
      ?,
      ?,
      ?
    ) [23502-214]
	at org.apache.ibatis.executor.BatchExecutor.doFlushStatements(BatchExecutor.java:149)
	at org.apache.ibatis.executor.BaseExecutor.flushStatements(BaseExecutor.java:129)
	at org.apache.ibatis.executor.BaseExecutor.flushStatements(BaseExecutor.java:122)
	at org.apache.ibatis.executor.CachingExecutor.flushStatements(CachingExecutor.java:114)
	at org.apache.ibatis.session.defaults.DefaultSqlSession.flushStatements(DefaultSqlSession.java:252)
	... 21 common frames omitted

Doing a longer analysis I came to the conclusion that the problem is with the CustomBatchBuilder.
In that unit test I’m starting a process instance which contains a task doing the following:

		// create batch job for deleting the data (to be watched in Camunda Cockpit)
		CustomBatchBuilder.of(idList)
			.configuration(delegateExecution.getProcessEngine().getProcessEngineConfiguration())
			.jobHandler(deleteHistoricDataJobHandler)
			.jobsPerSeed(appCleanupConfigProperties.getJobsPerSeed())
			.invocationsPerBatchJob(appCleanupConfigProperties.getInvocationsPerBatchJob())
			.exclusive(true)
			.create();

create() will create an instance of HistoricBatchEntity and stores it in the database. This will lead to the error with a delay since the JDBC operation is being batched and executed at the end of the transaction.

What could be the cause?
CustomBatchBuilder instantiates BatchEntity with startTime being null. This null value is being copied in DefaultHistoryEventProducer#createBatchEvent (line 1059) to the instance of HistoricBatchEvent. As far as I understand, this event becomes the entity which is being stored and fails the database’s “Not null constraint” for ACT_HI_BATCH.START_TIME_.

How to fix this?
I found no way to set startTime by myself. I can see that it’s being set by BatchBuilder#configure(), but not so for CustomBatchBuilder.

I’m glad for any advise what I’m doing wrong here.

Hi,

It looks like someone fixed your problem here already: Camunda bpm 7.18 failed to start · Issue #51 · camunda-community-hub/camunda-platform-7-custom-batch · GitHub

And there is a release 1.18.0 that includes the fix.

Cheers,
Thorben

2 Likes

Thanks, Thorben!
I chose version 1.18.1, which is also available on Maven Central. The only pitfall is that the artifact’s GroupID and ArtifactID have changed. So other readers need to change their dependency to:

<!-- https://mvnrepository.com/artifact/org.camunda.community.batch/camunda-platform-7-custom-batch-core -->
<dependency>
    <groupId>org.camunda.community.batch</groupId>
    <artifactId>camunda-platform-7-custom-batch-core</artifactId>
    <version>1.18.1</version>
</dependency>

Great, thanks for sharing!