Commit Objects Using Java Action

2
Hi all, I have a long-running process that is triggered by multiple scheduled events. The idea behind it is to get the process running concurrently using the scheduled events. However, this does open up the possibility for objects to be processed multiple times. To counter this I have a ‘Processing’ Boolean attribute, which I want to set at the beginning of the process. I tried to commit the objects (with the ‘Processing’ Boolean set to true) using a Java Action, but the ‘update’ is not showing in the transactions that follow (which are triggered by the other scheduled events). To my knowledge, Java Actions are separate transactions and therefore this should be possible. Any advice would be appreciated on how I can achieve it!
asked
2 answers
1

In the end, I found a Java Action called ‘commitInSeparateDatabaseTransaction’ in the CommunityCommons module. This Java action only takes a single object. I duplicated the Java Action and altered it to accept a list instead of a single object (basically just changing the input parameter type). And that’s it!

answered
-1

Java actions are still running in the same transaction as the calling microflow. The changes will only be visible in another context when the transaction is terminated.

There are options to run actions in a seperate transaction. The community commons should have java actions to manually start and end a transaction. But i would be carefull with that.

Did you consider using the process queue and do the actual processing there? Your scheduled event could retrieve the batch that is supposed to be processed, set the flag and create a Queued Action for this batch. At this moment, the transaction is done and the changes (the processing flag) will be reflected in the database. The process queue would now pick up the queued action and do the actual processing on your objects.

answered