-
1. Re: Get subprocess id from outside the process
rebody Aug 1, 2010 10:20 PM (in response to matrixpooh)Hi Al,
There is a new API in org.jbpm.api.Exection interface in jBPM-4.4. named getSubProcessInstance(). You could use it to get related sub process instance of an execution.
In jBPM-4.3, this method wasn't expose in API interface, so you have to cast class by yourself and get related sub process instance from ExecutionImpl.
-
2. Re: Get subprocess id from outside the process
matrixpooh Aug 2, 2010 10:48 AM (in response to rebody)Thanks for help, HuiSheng, but it still doesn't work:
Execution exe = processInstance.findActiveExecutionIn("subprocess-task"); String subprocessid = ((ExecutionImpl)execution).getSubprocessInstance(); -- fails with org.hibernate.LazyInitializationException:could not initialize proxy - no Session
Modified jbpm.execution.hbm.xml to do eager fetching. Works now.
<many-to-one name="subProcessInstance" ... lazy="false"/>
-
3. Re: Get subprocess id from outside the process
mwohlf Aug 2, 2010 10:36 AM (in response to matrixpooh)use a command:
processEngine.execute(new Command() {
public Object execute(Environment env) {
Execution exe = processInstance.findActiveExecutionIn("subprocess-task");
String subprocessid = ((ExecutionImpl)execution).getSubprocessInstance();System.out.printlnl("subprocessid is: " + subprocessid);
return null;
}
}); -
4. Re: Get subprocess id from outside the process
matrixpooh Aug 2, 2010 11:01 AM (in response to mwohlf)final Execution exectution = processInstance.findActiveExecutionIn("subprocess"); String pid = processEngineFactory.getProcessEngine().execute( new Command<String>(){ public String execute(Environment env){ return ((ExecutionImpl)execution).getSubProcessInstance().getId(); } } );
fails with LazyInitializationException - i.e. the same exception as before
-
5. Re: Get subprocess id from outside the process
mwohlf Aug 2, 2010 11:21 AM (in response to matrixpooh)that's interesting,
the following code should check for the hibernate session in your environment:
processEngine.execute(
new Command(){
public String execute(Environment env){
org.hibernate.Session session = env.get(org.hibernate.Session.class);
System.out.println("session is: " + session);
return null;
}
}
);if it is null you might have a problem in the session config for your tests, but then there should be way more problems, are you running other tests that pass? Also note you had "exectution" and "execution" in the code fragment.
-
6. Re: Get subprocess id from outside the process
matrixpooh Aug 2, 2010 1:44 PM (in response to mwohlf)My company disables copy/paste of the content. I had to type in the code manually so must've mistyped the variables. The session is definitely present.
-
7. Re: Get subprocess id from outside the process
mwohlf Aug 2, 2010 2:45 PM (in response to matrixpooh)1 of 1 people found this helpfulI tried to reproduce this issue so I added a testcase to
org.jbpm.examples.subprocess.outcomeactivity.SubProcessOutcomeActivityTest
but the following testcase passed for me:
public void testSubProcessIdQuery() { ProcessInstance processInstance = executionService.startProcessInstanceByKey("SubProcessDocument"); final Execution execution = processInstance.findActiveExecutionIn("review"); assertNotNull(execution); assertNotNull(processEngine); String pid = ((ExecutionImpl) execution).getSubProcessInstance().getId(); assertNotNull(pid); List<Task> taskList = taskService.findPersonalTasks("johndoe"); Task task = taskList.get(0); taskService.completeTask(task.getId(), "reject"); }
so maybe if you post your testcase someone is able to shed some light on this
-
8. Re: Get subprocess id from outside the process
matrixpooh Aug 4, 2010 3:13 PM (in response to mwohlf)Tried with the SubProcessOutcomeActivityTest - worked like a charm. Extended the process defnition to include <foreach /> - still works
Looking into specifics of my process defnitions. Will keep you posted.
Thanks a bunch for your help!