here is how you could define command and execute it on ksession so it gets executed within transaction
ksession.execute(new GenericCommand<Void>() {
public Vold execute(Context context) {
StatefulKnowledgeSession ksession = ((KnowledgeCommandContext) context).getStatefulKnowledgesession();
org.jbpm.process.instance.ProcessInstance processInstance = (org.jbpm.process.instance.ProcessInstance) ksession.getProcessInstance(piId);
// put your logic here
}
});
HTH