-
Bug
-
Resolution: Done
-
Major
-
jBPM 3.2.0
-
None
There was fixed issue "delete sub process instances recursively" (see http://jira.jboss.com/jira/browse/JBPM-614) that has been fixed.
Sub processes are deleted using following code:
-------------------------------------------------------------------------------------------------------------------
ProcessInstance subProcessInstance = token.getSubProcessInstance();
if (subProcessInstance != null)
-----------------------------------------------------------------------------------------------------------------------
The problem is that token.getSubProcessInstance() returns something only while token is in process state, as soon as token leaves process state, getSubProcessInstance() returns null.
The correct way to find sub process instances for current process is to query process instance by super process token, there is already defined named query in hibernate.queries.hbm.xml file - "GraphSession.findSubProcessInstances", so code should look following:
----------------------------------------------------------------------------------------------------------------------
Query query = session
.getNamedQuery("GraphSession.findSubProcessInstances");
query.setLong("instanceId", token.getProcessInstance().getId());
List<ProcessInstance> processInstances = query.list();
if (processInstances == null || processInstances.isEmpty())
return;
for (ProcessInstance instance : processInstances)
{ instance.setSuperProcessToken(null); token.setSubProcessInstance(null); deleteProcessInstance(instance); }---------------------------------------------------------------------------------------------------------------------------