cancel
Showing results for 
Search instead for 
Did you mean: 

activiti didn't check uniqueness of businessKey ?

quaff
Champ in-the-making
Champ in-the-making
http://activiti.org/javadocs/org/activiti/engine/RuntimeService.html#startProcessInstanceByKey(java.lang.String, java.lang.String, java.util.Map)
<blockcode>
The combination of processdefinitionKey-businessKey must be unique.
</blockcode>

I'm using activiti 5.15.1,I found I can start same processdefinitionKey-businessKey more than one times.

runtimeService.startProcessInstanceByKey("key","number");
runtimeService.startProcessInstanceByKey("key","number");
runtimeService.startProcessInstanceByKey("key","number");

I'm expecting throws exception and rollback transaction.
8 REPLIES 8

trademak
Star Contributor
Star Contributor
In Activiti 5.15 this behavior was changed, because there are use cases where you want to use the same business key multiple times. If you still want uniqueness for the business key, you can implement a process start listener that validates this.

Best regards,

quaff
Champ in-the-making
Champ in-the-making
I think activiti should add a option to processEngineConfiguration, and default behaviour is check uniqueness for back compatibility.Implementing listener is too tedious if I want all process check uniqueness.
would you improve it in next release? thanks very much.

trademak
Star Contributor
Star Contributor
We previously did this check on a database level. So it does mean a change to bring this functionality back. I don't agree that the listener is tedious, because you can write a parse handler so that the listener is added to each process definition automatically. But we could provide this listener out of the box with a engine configuration item, yes. Could you create a JIRA issue for this?

Best regards,

quaff
Champ in-the-making
Champ in-the-making

ssun
Champ on-the-rise
Champ on-the-rise
I vote for unique business key for active process instances. But if the previous process instance with the same business key is completed, you should be able to create a new one with the same key. Can we have that as one configuration?

I have a use case myself: our company bought a batch of tracking numbers from a package carrier. We go through them in around half a year and they will be re-used. They track different physical packages but there are no confusions because the old one should have been closed half a year ago. I totally see myself in near future create workflow for tracking the packages and need to use the tracking number as the business key.

My understanding is that this is not the case back in 5.14 (which is what I'm using now). What I don't understand is why it was like that. The completed processes are moved to history table, right? How could there have been a table level constraint?

trademak
Star Contributor
Star Contributor
Hi Gordon,

We can make it configurable to have no unique check, active unique check, and full unique check also across historic instances, yes.
In 5.14 and earlier there's a constraint on the runtime and historic process instance table on business key. So there are basically two table level constraints.

Best regards,

ssun
Champ on-the-rise
Champ on-the-rise
Thank you trademak! Those 3 level of checks in configuration sounds awesome to me. Hope to see it soon!

Best wishes!

–Gordon

ssun
Champ on-the-rise
Champ on-the-rise
Another issue I just encountered. It seems that even in 5.14, you can have same businessKey for 2 versions of the workflow definition.