Using Hibernate Session in JBPM 3 is quite simple, all you need is retrieving the Hibernate Session from the JbpmContext interface.
Below is a sample code which delete all process instances, by iterating on the ProcessInstance List:
public void deleteProcessInstances() {
JbpmContext context = JbpmConfiguration.getInstance().createJbpmContext();
try {
context.setSession(sessionFactory.getCurrentSession());
Session hibernateSession = context.getSession();
Query processQuery = hibernateSession.createQuery("from org.jbpm.graph.exe.ProcessInstance pi ");
List instances = (List) processQuery.list();
if (instances != null && instances.size() > 0) {
for (ProcessInstance instance : instances) {
long id = instance.getId();
instance.end();
context.getGraphSession().deleteProcessInstance(instance);
}
}
hibernateSession.flush();
}
finally {
context.close();
}
}