# Duplicate SQL insert primary key error in ACT\_HI\_\* tables in workflow

**URL:** <https://forum.flowable.org/t/duplicate-sql-insert-primary-key-error-in-act-hi-tables-in-workflow/6064>\
**Category:** Flowable Engine\
**Created:** [May 21, 2020, 5:50am UTC](https://forum.flowable.org/t/duplicate-sql-insert-primary-key-error-in-act-hi-tables-in-workflow/6064 "2020-05-21T05:50:04Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![amitshukla](https://avatars.discourse-cdn.com/v4/letter/a/7c8e57/32.png) [@amitshukla](https://forum.flowable.org/u/amitshukla)\
**Post date:** [May 21, 2020, 5:50am UTC](https://forum.flowable.org/t/duplicate-sql-insert-primary-key-error-in-act-hi-tables-in-workflow/6064/1 "2020-05-21T05:50:04Z")

</div>

Hi,

I have been using flowable v6.2.0 in a springboot application v1.5.7. Its been more than a year since I integrated flowable engine and it is working like a charm until yesterday I faced some weird issues on production server. After checking the log lines, there were random errors in flowable manged history tables.

ERROR o.f.e.c.i.interceptor.CommandContext.logException - Error while closing command context  
org.apache.ibatis.exceptions.PersistenceException:  
Error updating database. Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Duplicate entry ‘3381’ for key ‘PRIMARY’  
The error may involve org.flowable.identitylink.service.impl.persistence.entity.HistoricIdentityLinkEntityImpl.bulkInsertHistoricIdentityLink-Inline  
The error occurred while setting parameters  
SQL: insert into ACT\_HI\_IDENTITYLINK (ID\_, TYPE\_, USER\_ID\_, GROUP\_ID\_, TASK\_ID\_, PROC\_INST\_ID\_, CREATE\_TIME\_) values (?, ?, ?, ?, ?, ?, ?) , (?, ?, ?, ?, ?, ?, ?)  
Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Duplicate entry ‘3381’ for key ‘PRIMARY’

20-05-2020 07:05:43.551 [http-nio-8090-exec-24] ERROR o.f.e.c.i.interceptor.CommandContext.logException - Error while closing command context  
org.apache.ibatis.exceptions.PersistenceException:  
Error updating database. Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Duplicate entry ‘2957’ for key ‘PRIMARY’  
The error may involve org.flowable.variable.service.impl.persistence.entity.HistoricVariableInstanceEntityImpl.bulkInsertHistoricVariableInstance-Inline  
The error occurred while setting parameters  
SQL: insert into ACT\_HI\_VARINST (ID\_, PROC\_INST\_ID\_, EXECUTION\_ID\_, TASK\_ID\_, NAME\_, REV\_, VAR\_TYPE\_, SCOPE\_ID\_, SUB\_SCOPE\_ID\_, SCOPE\_TYPE\_, BYTEARRAY\_ID\_, DOUBLE\_, LONG\_ , TEXT\_, TEXT2\_, CREATE\_TIME\_, LAST\_UPDATED\_TIME\_) values ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? ) , ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? )  
Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Duplicate entry ‘2957’ for key ‘PRIMARY’

20-05-2020 08:15:18.736 [http-nio-8090-exec-24] ERROR c.i.z.core.services.RequestService.submitRequest -  
Error updating database. Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Duplicate entry ‘3422’ for key ‘PRIMARY’  
The error may involve org.flowable.engine.impl.persistence.entity.HistoricActivityInstanceEntityImpl.bulkInsertHistoricActivityInstance-Inline  
The error occurred while setting parameters  
SQL: insert into ACT\_HI\_ACTINST ( ID\_, REV\_, PROC\_DEF\_ID\_, PROC\_INST\_ID\_, EXECUTION\_ID\_, ACT\_ID\_, TASK\_ID\_, CALL\_PROC\_INST\_ID\_, ACT\_NAME\_, ACT\_TYPE\_, ASSIGNEE\_, START\_TIME\_, END\_TIME\_, DURATION\_, DELETE\_REASON\_, TENANT\_ID\_ ) values (?, 1, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) , (?, 1, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)  
Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Duplicate entry ‘3422’ for key ‘PRIMARY’

Error updating database. Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Duplicate entry ‘3458’ for ke  
y ‘PRIMARY’  
The error may involve org.flowable.task.service.impl.persistence.entity.HistoricTaskInstanceEntityImpl.insertHistoricTaskInstance-Inline  
The error occurred while setting parameters  
SQL: insert into ACT\_HI\_TASKINST ( ID\_, REV\_, PROC\_DEF\_ID\_, PROC\_INST\_ID\_, EXECUTION\_ID\_, SCOPE\_ID\_, SUB\_SCOPE\_ID\_, SCOPE\_TYPE\_, SCOPE\_DEFINITION\_ID\_, NAME\_, PARENT\_TASK\_ID\_, DESCRIPTION\_, OWNER\_, ASSIGNEE\_, START\_TIME\_, CLAIM\_TIME\_, END\_TIME\_, DURATION\_, DELETE\_REASON\_, TASK\_DEF\_KEY\_, FORM\_KEY\_, PRIORITY\_, DUE\_DATE\_, CATEGORY\_, TENANT\_ID\_, LAST\_UPDATED\_TIME\_ ) values ( ?, 1, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? )  
Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Duplicate entry ‘3458’ for key ‘PRIMARY’

I have no clue what suddenly happened and why it started to throw these duplicate primary key errors on production server. There were lot of workflow tasks failing to complete. I rebooted the server and everything seems to be fine now but I am afraid this can happen anytime in the future.

Please guide and let me know how I could fix this.  
Awaiting for a quick response

Thanks

---

<div class="post-metadata">

**Author:** ![amitshukla](https://avatars.discourse-cdn.com/v4/letter/a/7c8e57/32.png) [@amitshukla](https://forum.flowable.org/u/amitshukla)\
**Post date:** [May 25, 2020, 11:56am UTC](https://forum.flowable.org/t/duplicate-sql-insert-primary-key-error-in-act-hi-tables-in-workflow/6064/2 "2020-05-25T11:56:08Z")

</div>

Awaiting for a reply…Please help

---

<div class="post-metadata">

**Author:** ![filiphr](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/filiphr/32/315_2.png) [@filiphr](https://forum.flowable.org/u/filiphr)\
**Post date:** [May 25, 2020, 7:52pm UTC](https://forum.flowable.org/t/duplicate-sql-insert-primary-key-error-in-act-hi-tables-in-workflow/6064/3 "2020-05-25T19:52:49Z")

</div>

Hey @amitshukla,

Are you running multiple instances of the application? Did this happen during a high load of the application?

The version you are using from Flowable is old and uses the `DbIdGenerator`. In newer version the default `IdGenerator` when using Spring Boot is the `StrongUuidGenerator`. I would advise to either upgrade your Flowable version or configure your current one to use the `StrongUuidGenerator`.

Cheers,  
Filip

---

<div class="post-metadata">

**Author:** ![amitshukla](https://avatars.discourse-cdn.com/v4/letter/a/7c8e57/32.png) [@amitshukla](https://forum.flowable.org/u/amitshukla)\
**Post date:** [May 26, 2020, 5:02am UTC](https://forum.flowable.org/t/duplicate-sql-insert-primary-key-error-in-act-hi-tables-in-workflow/6064/4 "2020-05-26T05:02:33Z")

</div>

@filiphr so we have multi-tenant setup with each tenant having separate database. So based on request headers we identify the tenant and then do further transactions corresponding to the tenant. The load was around 5-10% at that moment both on application server and database.

Just quick questions based on your helpful advise

1. If I do an upgrade of Flowable version, will there be any impact on current workflow tasks which are in process/pending for completion on users/group of users ?
2. Where can I configure StrongUuidGenerator for workflow managed tables ?

Please guide and thank you so much for the reply.

---

<div class="post-metadata">

**Author:** ![filiphr](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/filiphr/32/315_2.png) [@filiphr](https://forum.flowable.org/u/filiphr)\
**Post date:** [May 26, 2020, 6:52am UTC](https://forum.flowable.org/t/duplicate-sql-insert-primary-key-error-in-act-hi-tables-in-workflow/6064/5 "2020-05-26T06:52:05Z")

</div>

> [@amitshukla](#):
>
> 1. If I do an upgrade of Flowable version, will there be any impact on current workflow tasks which are in process/pending for completion on users/group of users ?

They will continue running as before with the definitions you have deployed.

> [@amitshukla](#):
>
> 1. Where can I configure StrongUuidGenerator for workflow managed tables ?

I think that in 6.2.0 you’ll need to provide a bean of type `ProcessEngineConfigurationConfigurer` and configure the engine via it. You can set it on the engine.

In the newest version you only need to provide a bean of type `IdGenerator`.

Cheers,  
Filip

---

<div class="post-metadata">

**Author:** ![amitshukla](https://avatars.discourse-cdn.com/v4/letter/a/7c8e57/32.png) [@amitshukla](https://forum.flowable.org/u/amitshukla)\
**Post date:** [May 27, 2020, 5:49am UTC](https://forum.flowable.org/t/duplicate-sql-insert-primary-key-error-in-act-hi-tables-in-workflow/6064/6 "2020-05-27T05:49:39Z")

</div>

Thank you so much @filiphr for a quick response and help. Will try this and let you know.

---

<div class="post-metadata">

**Author:** ![amitshukla](https://avatars.discourse-cdn.com/v4/letter/a/7c8e57/32.png) [@amitshukla](https://forum.flowable.org/u/amitshukla)\
**Post date:** [October 5, 2020, 11:29am UTC](https://forum.flowable.org/t/duplicate-sql-insert-primary-key-error-in-act-hi-tables-in-workflow/6064/7 "2020-10-05T11:29:11Z")

</div>

@filiphr I configured StrongUuidGenerator and dint get the same error until today. So again the same error appeared in application log file and it was random some users were facing this error while taking an action while some dint face any issue.

This is how I have configured it creating a class file

> package com.inventiahealthcare.zygote.configs;
> 
> import org.flowable.engine.common.impl.persistence.StrongUuidGenerator;  
> import org.flowable.spring.SpringProcessEngineConfiguration;  
> import org.flowable.spring.boot.ProcessEngineConfigurationConfigurer;  
> import org.springframework.context.annotation.Bean;  
> import org.springframework.context.annotation.Configuration;
> 
> @Configuration  
> public class FlowableConfigurationConfiguration {
> 
> ```
> @Bean
> public FlowableConfigurationConfiguration flowableConfiguration() {
> return new FlowableConfigurationConfiguration();
> }
> 
> ```
> 
> }  
> class FlowableConfiguration implements ProcessEngineConfigurationConfigurer {
> 
> ```
> @Override
> public void configure(SpringProcessEngineConfiguration config) {
> config.setIdGenerator(new StrongUuidGenerator());
> }
> 
> ```
> 
> }

Please let me know how I can fix this once and for all as the user’s are suffering once a week and have to rerun the java service and everything works fine then after.

---

<div class="post-metadata">

**Author:** ![amitshukla](https://avatars.discourse-cdn.com/v4/letter/a/7c8e57/32.png) [@amitshukla](https://forum.flowable.org/u/amitshukla)\
**Post date:** [October 7, 2020, 4:47am UTC](https://forum.flowable.org/t/duplicate-sql-insert-primary-key-error-in-act-hi-tables-in-workflow/6064/8 "2020-10-07T04:47:34Z")

</div>

Waiting for your reply as how should I configure it correctly so that this issue never appears again. Also even if I upgrade to latest flowable version what difference it would make as even the latest version is using strongUuidGenerator method and I already implemented that but failed.

---

<div class="post-metadata">

**Author:** ![filiphr](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/filiphr/32/315_2.png) [@filiphr](https://forum.flowable.org/u/filiphr)\
**Post date:** [October 7, 2020, 6:26am UTC](https://forum.flowable.org/t/duplicate-sql-insert-primary-key-error-in-act-hi-tables-in-workflow/6064/9 "2020-10-07T06:26:40Z")

</div>

Can you please share the logs from the new error?

---

<div class="post-metadata">

**Author:** ![amitshukla](https://avatars.discourse-cdn.com/v4/letter/a/7c8e57/32.png) [@amitshukla](https://forum.flowable.org/u/amitshukla)\
**Post date:** [October 12, 2020, 6:49am UTC](https://forum.flowable.org/t/duplicate-sql-insert-primary-key-error-in-act-hi-tables-in-workflow/6064/10 "2020-10-12T06:49:35Z")

</div>

@filiphr PFA the screenshots & log lines of the log if that helps.

```
29-09-2020 05:31:30.540 [http-nio-8090-exec-24] ERROR o.f.e.c.i.interceptor.CommandContext.logException - Error while closing command context
org.apache.ibatis.exceptions.PersistenceException: 
### Error updating database. Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Duplicate entry '10065' for key 'PRIMARY'
### The error may involve org.flowable.task.service.impl.persistence.entity.HistoricTaskInstanceEntityImpl.insertHistoricTaskInstance-Inline
### The error occurred while setting parameters
### SQL: insert into ACT_HI_TASKINST ( ID_, REV_, PROC_DEF_ID_, PROC_INST_ID_, EXECUTION_ID_, SCOPE_ID_, SUB_SCOPE_ID_, SCOPE_TYPE_, SCOPE_DEFINITION_ID_, NAME_, PARENT_TASK_ID_, DESCRIPTION_, OWNER_, ASSIGNEE_, START_TIME_, CLAIM_TIME_, END_TIME_, DURATION_, DELETE_REASON_, TASK_DEF_KEY_, FORM_KEY_, PRIORITY_, DUE_DATE_, CATEGORY_, TENANT_ID_, LAST_UPDATED_TIME_ ) values ( ?, 1, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? )
### Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Duplicate entry '10065' for key 'PRIMARY'
        at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30)
        at org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java:200)
        at org.apache.ibatis.session.defaults.DefaultSqlSession.insert(DefaultSqlSession.java:185)
        at org.flowable.engine.common.impl.db.DbSqlSession.flushRegularInsert(DbSqlSession.java:438)
        at org.flowable.engine.common.impl.db.DbSqlSession.flushInsertEntities(DbSqlSession.java:419)
        at org.flowable.engine.common.impl.db.DbSqlSession.flushInserts(DbSqlSession.java:402)
        at org.flowable.engine.common.impl.db.DbSqlSession.flush(DbSqlSession.java:291)
        at org.flowable.engine.common.impl.interceptor.CommandContext.flushSessions(CommandContext.java:193)
        at org.flowable.engine.common.impl.interceptor.CommandContext.close(CommandContext.java:63)
        at org.flowable.engine.common.impl.interceptor.CommandContextInterceptor.execute(CommandContextInterceptor.java:81)
        at org.flowable.spring.SpringTransactionInterceptor$1.doInTransaction(SpringTransactionInterceptor.java:49)
        at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:133)
        at org.flowable.spring.SpringTransactionInterceptor.execute(SpringTransactionInterceptor.java:46)
        at org.flowable.engine.common.impl.interceptor.LogInterceptor.execute(LogInterceptor.java:30)
        at org.flowable.engine.common.impl.cfg.CommandExecutorImpl.execute(CommandExecutorImpl.java:56)
        at org.flowable.engine.common.impl.cfg.CommandExecutorImpl.execute(CommandExecutorImpl.java:51)
        at org.flowable.engine.impl.TaskServiceImpl.complete(TaskServiceImpl.java:215)
        at com.inventiahealthcare.zygote.utils.ActivityManager.completeTask(ActivityManager.java:106)
        at com.inventiahealthcare.zygote.core.services.ImpactedUnitService.submitAssessment(ImpactedUnitService.java:299)
        at com.inventiahealthcare.zygote.core.services.ImpactedUnitService$$FastClassBySpringCGLIB$$140ed117.invoke(<generated>)

```

Also Please find the configuration of the main class the way I have configured

```
@SpringBootApplication(exclude = {org.flowable.spring.boot.SecurityAutoConfiguration.class, 
		DataSourceAutoConfiguration.class, 
		DataSourceTransactionManagerAutoConfiguration.class})
@EnableResourceServer
@EnableScheduling
@EnableTransactionManagement
public class ZygoteApplication {
           ...
}

```

Past 2 weeks I have not encountered similar issue of duplicate entry in workflow history table and everything is working just fine. When ever this issue occurs, I have to restart the application service and then everything is back to normal.

 ![Screenshot from 2020-10-12 11-33-44](https://canada1.discourse-cdn.com/flex035/uploads/flowable/original/2X/6/65740ef571097afcd355d568e73fafd52059e282.png) ![Screenshot from 2020-10-12 11-33-26](https://canada1.discourse-cdn.com/flex035/uploads/flowable/original/2X/8/8358659cb827f9b7953f7a922bf9d089f1f4cb65.png) ![Screenshot from 2020-10-12 11-31-35](https://canada1.discourse-cdn.com/flex035/uploads/flowable/original/2X/d/d491cef315366d0d03780c6205a26f157f237c7b.png) ![Screenshot from 2020-10-12 11-31-06](https://canada1.discourse-cdn.com/flex035/uploads/flowable/original/2X/5/551e6abf4abdd8175c2e0695d074cf47bacac627.png)

---

<div class="post-metadata">

**Author:** ![filiphr](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/filiphr/32/315_2.png) [@filiphr](https://forum.flowable.org/u/filiphr)\
**Post date:** [October 12, 2020, 7:18am UTC](https://forum.flowable.org/t/duplicate-sql-insert-primary-key-error-in-act-hi-tables-in-workflow/6064/11 "2020-10-12T07:18:24Z")

</div>

Hey @amitshukla,

> [@amitshukla](#):
>
> `Duplicate entry '10065' for key 'PRIMARY'`

This indicates that you are not using the `StrongUuidIdGenerator`. You should verify in your setup that the id generator is correctly set and not changed later by something else.

Cheers,  
Filip

---

<div class="post-metadata">

**Author:** ![amitshukla](https://avatars.discourse-cdn.com/v4/letter/a/7c8e57/32.png) [@amitshukla](https://forum.flowable.org/u/amitshukla)\
**Post date:** [October 12, 2020, 7:59am UTC](https://forum.flowable.org/t/duplicate-sql-insert-primary-key-error-in-act-hi-tables-in-workflow/6064/12 "2020-10-12T07:59:09Z")

</div>

@filiphr this is how I have configured

```
package com.inventiahealthcare.zygote.configs;

import org.flowable.engine.common.impl.persistence.StrongUuidGenerator;
import org.flowable.spring.SpringProcessEngineConfiguration;
import org.flowable.spring.boot.ProcessEngineConfigurationConfigurer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class FlowableConfigurationConfiguration {

    @Bean
    public FlowableConfigurationConfiguration flowableConfiguration() {
        return new FlowableConfigurationConfiguration();
    }
}

class FlowableConfiguration implements ProcessEngineConfigurationConfigurer {

    @Override
    public void configure(SpringProcessEngineConfiguration config) {
        config.setIdGenerator(new StrongUuidGenerator());
    }
}

```

Is this not the right way to configure ?  
How can I verify this?  
Is there any project for reference ?
