How Activiti generates database ID for managed entities?
Activiti BPM engine maintains database having 24 tables. Most of the tables has ID as primary key to identify a particular row in a given table. Activiti BPM engine with the help of Database ID generator implementation, generates next id to be used for any row to be persisted on any given table. The new ID which is generated using database ID generator makes use of db property "next.dbid" as the seed data to start with. Activiti process engine also maintains another parameter called block size (default value of 2500). Block size is the difference between any two subsequently generated database identifiers.
Probably one who wants to understand this property in action should look out for table act_ge_property under activiti database/schema. I am using MySQL to understand Activiti process engine's database model. I have shown a snapshot of database below.
FIG 1: Database property showing seed data for next database ID.
When activiti BPM process engine wants to persist an entity say User entity, it generates the database identifier (ID) for the new user entity using database ID generator using the combination of property value (next.dbid) and block size (typically by default, it is 2500).
The generation functionality happens in an entirely new transaction propogation. The database transaction propogation is set to "REQUIRES_NEW". Database ID generator is quite important piece of Activiti database management in terms of using one generator for most of the primary key requirements.
Database ID generator is the default strategy to generate ID for most of the entities managed by Activiti process engine. As long as Activiti user does mention ID for a given entity say Group, Activiti process engine makes sure that it makes use of user provided value as primary key for given entity instance say Group instance.
The database ID generator strategy can be customized by providing our own implementation for interface, org.activiti.engine.impl.cfg.IdGenerator. The current default implementation extends this java interface, org.activiti.engine.impl.db.DbIdGenerator. The implementation is under the package org.activiti.engine.impl.*. As mentioned by core team of Activiti process engine, the classes inside impl package are not stable in a sense that they might change at any time in future.
The implementation for getNextId() is a synchronized method. It always returns String value as ID for any requesting entity.
The implementation for getNextId() is a synchronized method. It always returns String value as ID for any requesting entity.
Really nice post about the topic. Took me 2 days to repair the db by inserting the next.dbId property :)
ReplyDeleteI need to update the Comment for closed Task
ReplyDeleteBut the this is not available for activiti
https://forums.activiti.org/content/add-comment-ended-process-instance
can I insert the the comment in ACT_HI_COMMET table directly with process instance id by generating the sequence of ID_