with persistence enabled the ProcessInstance returned from startProcess will reflect only the state of the process instance until last wait state. Then when you signal process instance you will need to fetch the instance vie ksession.getProcessInstance to see any updates to it and I believe then you will get null as process instance has been completed.
I think process state is the side effect of that process does not complete properly or at least been marked as complete.
Following is the database records for P1 and P2 mentioned in previous post.
P1 has processInstanceId of 16 while P2 has 15.
In processinstancelog table, we can see P2 is in complete state (status = 2) and P1 is in active state (status = 1 + both duration and end_date are null)
In processinstanceinfo table, I cannot find any record with InstanceId of 15 or 16, so I recon both P1 and P2 finish running.
and this is the code snippet (important part is highlight in blue) I used to fire signalEvent() and getState() on P1.
ds = new PoolingDataSource();
kservices = KieServices.Factory.get();
kstore = kservices.getStoreServices();
environment = kservices.newEnvironment();
EntityManagerFactory emf = Persistence.createEntityManagerFactory("org.jbpm.persistence.jpa");
TransactionManager tm = TransactionManagerServices.getTransactionManager();
ksconf = kservices.newKieSessionConfiguration();
kbase = kservices.getKieClasspathContainer().getKieBase();
ksession = kstore.loadKieSession(sessionId, kbase, ksconf, environment);
ProcessInstance processInstance = ksession.getProcessInstance(pid);
ksession.signalEvent(signal, data, pid);
I just don't know why signalEvent() can put process into complete state when persistence is disabled and leave process in active state when persistence is enabled.
Is there any extra steps to be taken when persistence is enabled?
I take one further step by examining nodeinstancelog table.
Please refer to the following observation in case you need more information.
for process instance #15 that completes properly, the node instance id is in perfect mirror.
eg. 0 -> 1 -> 2 -> 3 -> 3 -> 2 -> 1 -> 0
where node id #3 appears twice
for process instance #16 that remains active but is actually completed, the node instance id has one node id missing.
eg. 0 -> 1 -> 2 -> 3 -> 2 -> 1 -> 0
where node id #3 only appears once
1 of 1 people found this helpful
the problem with your code is that you don't register logger on your ksession and that's why processinstancelog table does not have log records while processinstance is actually completed.
I would recommend using RuntimeManager based code to avoid such issues. See jbpm docs for details about both JPA db logger on ksession and runtime manager.
Thank you Maciej,
In jbpm docs, I see there is a JPAWorkingMemoryDbLogger. (Chapter 8. Core Engine: Persistence and transactions)
When I try to find a logger for real DB (not in memory DB), I cannot find one.
Do you mind to provide an example or relative document link?
same logger shall be used regardless of the data base type. The name is WorkingMemory and not MemoryDB