AnsweredAssumed Answered

about the process instance business key

Question asked by heymjo on Nov 22, 2011
Latest reply on Jan 8, 2015 by funvin

I think that the business key concept in Activiti needs to be clarified. Currently there are 2 restrictions in Activiti with regards to this key AFAICT:

1) there cannot be 2 active process instances with the same business key:

alter table ACT_RU_EXECUTION
    add constraint ACT_UNIQ_RU_BUS_KEY
    unique(PROC_DEF_ID_, BUSINESS_KEY_);

2) the process history is not capable of recording 2 instances of the same process definition with the same business key

alter table ACT_HI_PROCINST
    add constraint ACT_UNIQ_HI_BUS_KEY
    unique(PROC_DEF_ID_, BUSINESS_KEY_);

In a way this is already conflicting IMO. I can start a process instance with key abc, complete it and then start a new one with the same key, but won't be able to complete() it because the history auditing will throw a unique key violation.

So, conceptually, what is the business key meant to be used for ? If we should use it to assign an application level reference to the process instance, why is it so restrictive ? IMO Activiti should not make any assumption for a business process and just let it start a process with whatever it thinks is meaningful for the business key. If the business allows starting 2 process instances for the same business entity so be it.

On the other hand, if Activiti insists on having unique business keys per process instance it should not allow us to start the process in the first place. That would require a (potentially expensive) history lookup on each process start, which is not ideal either.

See also