cancel
Showing results for 
Search instead for 
Did you mean: 

Cannot insert duplicate key

al_lv
Champ in-the-making
Champ in-the-making
Hallo,
I get this message afte runing my workflow.

Cannot insert duplicate key row in object 'ACT_RU_EXECUTION' with unique index 'ACT_UNIQ_RU_BUS_KEY'.

this a part of a staktrace:

INFO: Email task was succesfully completed.
14.07.2011 15:41:09 org.activiti.engine.impl.interceptor.CommandContext close
SCHWERWIEGEND: Error while closing command context
org.apache.ibatis.exceptions.PersistenceException:
### Error updating database.  Cause: java.sql.SQLException: Cannot insert duplicate key row in object 'ACT_RU_EXECUTION' with unique index 'ACT_UNIQ_RU_BUS_KEY'.
### The error may involve org.activiti.engine.impl.persistence.entity.ExecutionEntity.insertExecution-Inline
### The error occurred while setting parameters
### Cause: java.sql.SQLException: Cannot insert duplicate key row in object 'ACT_RU_EXECUTION' with unique index 'ACT_UNIQ_RU_BUS_KEY'.
   at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:8)
   at org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java:100)


I cann't understand what it wants and how can I fix it.
It happend with fresh builded database also.
I use activiti 5.6 and MsSQL.
Please help

Thanks

Alexej
12 REPLIES 12

micha1
Champ on-the-rise
Champ on-the-rise
Hey there,

the exception you got means that you ignore the uniqueness of business keys.  I guess you start all your process instances (you call them workflows) with one and the same business key. So give every new workflow an own business key or start the workflows without business key and everything is fine.

   startProcessInstanceById(processDefinitionId, businessKey);
easier….
   startProcessInstanceById(processDefinitionId);

Best regards,
Micha

al_lv
Champ in-the-making
Champ in-the-making
Hey there,

the exception you got means that you ignore the uniqueness of business keys.  I guess you start all your process instances (you call them workflows) with one and the same business key. So give every new workflow an own business key or start the workflows without business key and everything is fine.

   startProcessInstanceById(processDefinitionId, businessKey);
easier….
   startProcessInstanceById(processDefinitionId);

Best regards,
Micha

Hi Micha,

Thank you for your answer.
But I use no business key in my process definition.
For starting I call startProcessInstanceByKey(workflowId, variables);. It should start the last version of process definition with my process variables.
I always redeploy the process definition, so there is only one version deployed.
The KEY is the ID of process definition.
<process name="siebel" id="siebel" >

Exception says:
SCHWERWIEGEND: Error while closing command context
So the problem is by closing of context
But than: Cause: java.sql.SQLException: Cannot insert duplicate key row in object 'ACT_RU_EXECUTION' with unique index 'ACT_UNIQ_RU_BUS_KEY'.
There is no business key…. Add what try it to insert?

This is my process:
[attachment=0]siebel_and_email.png[/attachment]

If I run a singel service task there is no problem.
So the problem is in runing of tow service tasks together.
But what I make false?
Both of them extends AbstractBpmnActivityBehavior and have execute method.
Both of the run perfectly also…

regards

Alexej

al_lv
Champ in-the-making
Champ in-the-making
I added execution.end(); at the end of my service tasks and now it runs perfectly.
BUT!!!
now I have anothe problem:
21.07.2011 14:55:53 org.activiti.engine.impl.interceptor.CommandContext close
SCHWERWIEGEND: Error while closing command context
org.apache.ibatis.exceptions.PersistenceException:
### Error updating database.  Cause: java.sql.SQLException: Cannot insert duplicate key row in object 'ACT_HI_PROCINST' with unique index 'ACT_UNIQ_HI_BUS_KEY'.
### The error may involve org.activiti.engine.impl.persistence.entity.HistoricProcessInstanceEntity.insertHistoricProcessInstance-Inline
### The error occurred while setting parameters
### Cause: java.sql.SQLException: Cannot insert duplicate key row in object 'ACT_HI_PROCINST' with unique index 'ACT_UNIQ_HI_BUS_KEY'.
at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:8)
at org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java:100)
at org.apache.ibatis.session.defaults.DefaultSqlSession.insert(DefaultSqlSession.java:87)


I quess the business key cannot be the same in the hole table. But I use no business key.
This is my 'ACT_HI_PROCINST' afte the process was run:
[attachment=0]Activiti Probe – Database_1311253858396.png[/attachment]

What is it business key? And why it shouldn't be a same by every process instance?

ronald_van_kuij
Champ on-the-rise
Champ on-the-rise
adding execution.end() should never be needed… What is it that you do in your service task? Run javacode? Can you show that?

al_lv
Champ in-the-making
Champ in-the-making
Yes, I'm running a java-Code.
This is the Email Task:

public void execute(ActivityExecution execution) throws Exception {
 
  try {
  LOG.info("Starting email task.");
  Map<String, Object> variables = new HashMap<String, Object>();
  variables = execution.getVariables();
   
  ConnectorBusinessData data = loadDataXml(variables.get("data"));
 
  JavaxEmailFactory mailFactory = new JavaxEmailFactory();
  mailFactory.createEmailService().sendEmail(data);
  LOG.info("Email task was succesfully completed.");
  }catch (Exception e) {
   LOG.severe("There is a problem with EmailTask: "
     + e.getMessage());
   execution.setVariable("exception", e.getMessage().getBytes());  
   throw XYException.wrap(e);
  }
  finally{
   execution.end();
  }
 
 
}

I found something else:
I've deleted the WHERE clause from SQL Skript:
File: activiti.mssql.create.history.sql
Line: 105
there is a statment for create uniq index, but with WHERE it doesn't work.
this message i get with WHERE:
[java] INFO: performing create on history with resource org/activiti/db/create/activiti.mssql.create.history.sql
[java] 21.07.2011 16:18:45 org.activiti.engine.impl.db.DbSqlSession executeSchemaResource
[java] SCHWERWIEGEND: problem during schema create, statement 'create unique index ACT_UNIQ_HI_BUS_KEY on ACT_HI_PROCINST (PROC_DEF_ID_, BUSINESS_KEY_) where BUSINESS_KEY_ is not null
[java] java.sql.SQLException: Incorrect syntax near the keyword 'where'.

trademak
Star Contributor
Star Contributor
Hi,

You didn't include a vital part of the code, which is the class definition.
Because I'm guessing you are implementing the ActivityBehavior interface, instead of the JavaDelegate interface.
The JavaDelegate interface is recommended, as stated in the user guide. Is there a specific reason why you are using the ActivityBehavior interface?
One of the things you have to take care of when using the ActivityBehavior interface is leaving the current task.
And then you should use execution.take(transition) method and certainly not execution.end().

Best regards,

al_lv
Champ in-the-making
Champ in-the-making
Hi,

Is there a specific reason why you are using the ActivityBehavior interface?
One of the things you have to take care of when using the ActivityBehavior interface is leaving the current task.
And then you should use execution.take(transition) method and certainly not execution.end().
,

The reason is exceptions handling and expressions.
I cann't use execution.take(transition), because the models from signavio-modeler have transitions with generated ID. Eclipse Designer can this, but my system should work in browser.

I tried it no without transitions and with JavaDelegate. It doesn't work. It still need ActivityBehavior for expressions.

How do I leave the current task from the Service Task Class?


And what about the error by ant db.create on MSSQL?
the line 105 in activiti.mssql.create.history.sql:
create unique index ACT_UNIQ_HI_BUS_KEY on ACT_HI_PROCINST (PROC_DEF_ID_, BUSINESS_KEY_) where BUSINESS_KEY_ is not null;
doesn't work properly.

may be the problem is PROC_DEF_ID_ in brackets. Should it be not PROC_INST_ID_ ?

al_lv
Champ in-the-making
Champ in-the-making
ANY ANSWER????

ronald_van_kuij
Champ on-the-rise
Champ on-the-rise
[size=50]shouting does not help[/size]