In my case I have business process that has callActivity. In some way subrocess ends in transaction where it was created. And when activiti flush transaction I see errors in database (incorrect foreign keys). That occurs because DbSqlSession.flushTransaction() calls removeUnnecessaryOperations(). This method removes INSERTs and DELETEs, but it doesn't delete variables assotiated with the execution. Foreign keys check in java code is very heavy task and I think hack sql operations is not good approach. Сan I create an option that will be turn off this optimization and create patch for trunk?
I also have an issue where in a certain scenario, I have a create task listener that tries to immediately complete the task. The call to removeUnnecessaryOperations does not do the task insert, and then the identity links which were not removed create a foreign key error.
I got around my problem by calling flush on dbsqlsession before completing the task. Is it OK to call flush from within a event listener? I looked at the code and all it seems to do is just execute the pending database statements and leave the current transaction alone. With this being the case, I am assuming that flush can safely be called.