Error: insertHistoricVariableInstance (batch index #1) failed

Hi,

i got the following error, when execution a servicetask:

org.camunda.bpm.engine.ProcessEngineException: ENGINE-03083 Exception while executing Batch Database Operations with message '
### Error flushing statements.  Cause: org.apache.ibatis.executor.BatchExecutorException: org.camunda.bpm.engine.impl.persistence.entity.HistoricVariableInstanceEntity.insertHistoricVariableInstance (batch index #1) failed. Cause: java.sql.BatchUpdateException: Zeichenfolgen- oder Binärdaten würden abgeschnitten.
### Cause: org.apache.ibatis.executor.BatchExecutorException: org.camunda.bpm.engine.impl.persistence.entity.HistoricVariableInstanceEntity.insertHistoricVariableInstance (batch index #1) failed. Cause: java.sql.BatchUpdateException: Zeichenfolgen- oder Binärdaten würden abgeschnitten.
java.sql.BatchUpdateException: Zeichenfolgen- oder Binärdaten würden abgeschnitten.
'. Flush summary: 
 [
  INSERT HistoricVariableInstanceEntity[39a9afaf-ac46-11e8-ac71-005056995c78]
  INSERT HistoricVariableInstanceEntity[39a9afb1-ac46-11e8-ac71-005056995c78]
  INSERT HistoricVariableInstanceEntity[39a9afb3-ac46-11e8-ac71-005056995c78]
  INSERT HistoricVariableInstanceEntity[39aa24e5-ac46-11e8-ac71-005056995c78]
  INSERT HistoricVariableInstanceEntity[39aa4bf7-ac46-11e8-ac71-005056995c78]
  INSERT HistoricVariableInstanceEntity[39aa4bf9-ac46-11e8-ac71-005056995c78]
  INSERT HistoricVariableInstanceEntity[39aa730b-ac46-11e8-ac71-005056995c78]
  INSERT HistoricVariableInstanceEntity[39aa730d-ac46-11e8-ac71-005056995c78]
  INSERT HistoricVariableInstanceEntity[39aa9a1f-ac46-11e8-ac71-005056995c78]
  INSERT HistoricVariableInstanceEntity[39aa9a21-ac46-11e8-ac71-005056995c78]
  INSERT HistoricVariableInstanceEntity[39aae843-ac46-11e8-ac71-005056995c78]
  INSERT HistoricVariableInstanceEntity[39b129d5-ac46-11e8-ac71-005056995c78]
  INSERT HistoricVariableInstanceEntity[39b129d7-ac46-11e8-ac71-005056995c78]
  INSERT HistoricVariableInstanceEntity[39b177f9-ac46-11e8-ac71-005056995c78]
  INSERT HistoricJobLogEventEntity[39b39add-ac46-11e8-ac71-005056995c78]
  INSERT HistoricJobLogEventEntity[39b39ade-ac46-11e8-ac71-005056995c78]
  INSERT HistoricVariableUpdateEventEntity[39a9afb0-ac46-11e8-ac71-005056995c78]
  INSERT HistoricVariableUpdateEventEntity[39a9afb2-ac46-11e8-ac71-005056995c78]
  INSERT HistoricVariableUpdateEventEntity[39a9afb4-ac46-11e8-ac71-005056995c78]
  INSERT HistoricVariableUpdateEventEntity[39aa24e6-ac46-11e8-ac71-005056995c78]
  INSERT HistoricVariableUpdateEventEntity[39aa4bf8-ac46-11e8-ac71-005056995c78]
  INSERT HistoricVariableUpdateEventEntity[39aa4bfa-ac46-11e8-ac71-005056995c78]
  INSERT HistoricVariableUpdateEventEntity[39aa730c-ac46-11e8-ac71-005056995c78]
  INSERT HistoricVariableUpdateEventEntity[39aa730e-ac46-11e8-ac71-005056995c78]
  INSERT HistoricVariableUpdateEventEntity[39aa9a20-ac46-11e8-ac71-005056995c78]
  INSERT HistoricVariableUpdateEventEntity[39aac132-ac46-11e8-ac71-005056995c78]
  INSERT HistoricVariableUpdateEventEntity[39aae844-ac46-11e8-ac71-005056995c78]
  INSERT HistoricVariableUpdateEventEntity[39b129d6-ac46-11e8-ac71-005056995c78]
  INSERT HistoricVariableUpdateEventEntity[39b129d8-ac46-11e8-ac71-005056995c78]
  INSERT HistoricVariableUpdateEventEntity[39b177fa-ac46-11e8-ac71-005056995c78]
  INSERT HistoricActivityInstanceEventEntity[BoundaryEvent_09i7tfk:39b2d78b-ac46-11e8-ac71-005056995c78]
  INSERT HistoricActivityInstanceEventEntity[Task_0hi9bsi:39a9889e-ac46-11e8-ac71-005056995c78]
  INSERT VariableInstanceEntity[39b129d5-ac46-11e8-ac71-005056995c78]
  INSERT VariableInstanceEntity[39b129d7-ac46-11e8-ac71-005056995c78]
  INSERT VariableInstanceEntity[39b177f9-ac46-11e8-ac71-005056995c78]
  INSERT MessageEntity[39b39adc-ac46-11e8-ac71-005056995c78]
  DELETE MessageEntity[39384fea-ac46-11e8-ac71-005056995c78]
  DELETE_BULK deleteByteArrayNoRevisionCheck 39694b28-ac46-11e8-ac71-005056995c78
  UPDATE ExecutionEntity[38e43c5e-ac46-11e8-ac71-005056995c78]
  DELETE ExecutionEntity[3934a666-ac46-11e8-ac71-005056995c78]
  UPDATE HistoricActivityInstanceEventEntity[SubProcess_15nl96a:3934cd77-ac46-11e8-ac71-005056995c78]
]
	at org.camunda.bpm.engine.impl.db.EnginePersistenceLogger.flushDbOperationsException(EnginePersistenceLogger.java:689)
	at org.camunda.bpm.engine.impl.db.entitymanager.DbEntityManager.flushDbOperations(DbEntityManager.java:343)
	at org.camunda.bpm.engine.impl.db.entitymanager.DbEntityManager.flushDbOperationManager(DbEntityManager.java:314)
	at org.camunda.bpm.engine.impl.db.entitymanager.DbEntityManager.flush(DbEntityManager.java:286)
	at org.camunda.bpm.engine.impl.interceptor.CommandContext.flushSessions(CommandContext.java:203)
	at org.camunda.bpm.engine.impl.interceptor.CommandContext.close(CommandContext.java:132)
	at org.camunda.bpm.engine.impl.interceptor.CommandContextInterceptor.execute(CommandContextInterceptor.java:113)
	at org.camunda.bpm.engine.impl.interceptor.ProcessApplicationContextInterceptor.execute(ProcessApplicationContextInterceptor.java:66)
	at org.camunda.bpm.engine.impl.interceptor.LogInterceptor.execute(LogInterceptor.java:30)
	at org.camunda.bpm.engine.impl.jobexecutor.ExecuteJobHelper.executeJob(ExecuteJobHelper.java:36)
	at org.camunda.bpm.engine.impl.jobexecutor.ExecuteJobHelper.executeJob(ExecuteJobHelper.java:29)
	at org.camunda.bpm.engine.impl.jobexecutor.ExecuteJobsRunnable.executeJob(ExecuteJobsRunnable.java:88)
	at org.camunda.bpm.engine.impl.jobexecutor.ExecuteJobsRunnable.run(ExecuteJobsRunnable.java:57)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
	at java.lang.Thread.run(Thread.java:745)
Caused by: org.apache.ibatis.exceptions.PersistenceException: 
### Error flushing statements.  Cause: org.apache.ibatis.executor.BatchExecutorException: org.camunda.bpm.engine.impl.persistence.entity.HistoricVariableInstanceEntity.insertHistoricVariableInstance (batch index #1) failed. Cause: java.sql.BatchUpdateException: Zeichenfolgen- oder Binärdaten würden abgeschnitten.
### Cause: org.apache.ibatis.executor.BatchExecutorException: org.camunda.bpm.engine.impl.persistence.entity.HistoricVariableInstanceEntity.insertHistoricVariableInstance (batch index #1) failed. Cause: java.sql.BatchUpdateException: Zeichenfolgen- oder Binärdaten würden abgeschnitten.
	at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30)
	at org.apache.ibatis.session.defaults.DefaultSqlSession.flushStatements(DefaultSqlSession.java:255)
	at org.camunda.bpm.engine.impl.db.sql.DbSqlSession.flushOperations(DbSqlSession.java:88)
	at org.camunda.bpm.engine.impl.db.entitymanager.DbEntityManager.flushDbOperations(DbEntityManager.java:341)
	... 14 more
Caused by: org.apache.ibatis.executor.BatchExecutorException: org.camunda.bpm.engine.impl.persistence.entity.HistoricVariableInstanceEntity.insertHistoricVariableInstance (batch index #1) failed. Cause: java.sql.BatchUpdateException: Zeichenfolgen- oder Binärdaten würden abgeschnitten.
	at org.apache.ibatis.executor.BatchExecutor.doFlushStatements(BatchExecutor.java:146)
	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:253)
	... 16 more
Caused by: java.sql.BatchUpdateException: Zeichenfolgen- oder Binärdaten würden abgeschnitten.
	at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.executeBatch(SQLServerPreparedStatement.java:1870)
	at sun.reflect.GeneratedMethodAccessor55.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.apache.tomcat.jdbc.pool.StatementFacade$StatementProxy.invoke(StatementFacade.java:114)
	at com.sun.proxy.$Proxy6.executeBatch(Unknown Source)
	at sun.reflect.GeneratedMethodAccessor55.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.apache.ibatis.logging.jdbc.PreparedStatementLogger.invoke(PreparedStatementLogger.java:78)
	at com.sun.proxy.$Proxy7.executeBatch(Unknown Source)
	at org.apache.ibatis.executor.BatchExecutor.doFlushStatements(BatchExecutor.java:122)
	... 20 more

I know, that a similar error occurs, when a string is to long for the history database, but i checked all variables, there is no long string. Another problem is, that the error is very rare and if i press retry in the cockpit, it works.
Is it possible to see, which variable should be insert to the history?

You can configure logging to print all SQL statements made by the engine to the log file as described here: Support for Hana database - #2 by thorben. This will also output the parameters.

Cheers,
Thorben

We included all this

org.apache.ibatis.level=DEBUG
org.camunda.bpm.engine.impl.persistence.level=DEBUG

org.camunda.bpm.engine.impl.persistence.entity.level = DEBUG;
org.camunda.bpm.engine.persistence.level = DEBUG
org.camunda.bpm.engine.impl.persistence.entity.level = DEBUG
org.camunda.bpm.engine.impl.history.event.level = DEBUG
org.camunda.bpm.engine.impl.batch.history.level = DEBUG
org.camunda.bpm.engine.impl.batch.level = DEBUG
org.camunda.bpm.engine.impl.cmmn.entity.repository.level = DEBUG
org.camunda.bpm.engine.impl.cmmn.entity.runtime.level = DEBUG
org.camunda.bpm.engine.impl.dmn.entity.repository.level = DEBUG
org.camunda.bpm.engine.history.level = DEBUG

in the logging.properties file without any success.

However, the problem is resolved now as we took a complete exception (> 4000 chars) as error message in a BpmnError and this lead to the error as camunda is (still) not able to store more than 4000 chars in the database per field.

Thanks for your help

Nice you could resolve it. On Tomcat, log level DEBUG is called FINE by the way.

Hey Nashorn, I have the exact same error as you do. Do you remember what you had to do to fix it? Any help is appreciated.

Thanks,
Daniel.

Hi,
this error occurs, when you try to save string with a length over 4000 chars to Camunda. You have to check the normal variables, the local variables (input/output on servicetask) as well as the error messages.
If you need a string over 4000 chars length, build a wrapper object and serialize the object, otherwise just truncate the string.