Hi,
I've made a small sample app that stores knowledge session into a H2 database, based on jBPM user guide.
{code}
PoolingDataSource ds = new PoolingDataSource();
ds.setUniqueName("jdbc/BitronixJTADataSource");
ds.setClassName("org.h2.jdbcx.JdbcDataSource");
ds.setMaxPoolSize(3);
ds.setAllowLocalTransactions(true);
ds.getDriverProperties().put("user", "sa");
ds.getDriverProperties().put("password", "");
ds.getDriverProperties().put("URL", "jdbc:h2:tcp://localhost/~/test");
ds.init();
EntityManagerFactory emf = Persistence.createEntityManagerFactory("org.jbpm.persistence.jpa");
// load up the knowledge base
KnowledgeBase kbase = readKnowledgeBase();
Environment env = KnowledgeBaseFactory.newEnvironment();
env.set(EnvironmentName.ENTITY_MANAGER_FACTORY, emf);
env.set(EnvironmentName.TRANSACTION_MANAGER, TransactionManagerServices.getTransactionManager());
Integer sessionId = null;
if (args != null && args.length == 1) {
sessionId = Integer.valueOf(args[0]);
}
StatefulKnowledgeSession ksession = null;
if (sessionId == null) {
// new session
ksession = JPAKnowledgeService.newStatefulKnowledgeSession(kbase, null, env);
} else {
// load existing session from database
ksession = JPAKnowledgeService.loadStatefulKnowledgeSession(sessionId, kbase, null, env);
}
// start the transaction
UserTransaction ut = (UserTransaction) new InitialContext().lookup("java:comp/UserTransaction");
ut.begin();
// start 5 new process instances
ksession.startProcess("com.sample.bpmn.hello");
ksession.startProcess("com.sample.bpmn.hello");
ksession.startProcess("com.sample.bpmn.hello");
ksession.startProcess("com.sample.bpmn.hello");
ksession.startProcess("com.sample.bpmn.hello");
ksession.dispose();
ut.commit();
{code}
For each knowledge session, 5 processes are created, and that process waits for a signal (it is not completed).
I have another application that loads knowledge session from database (by using ID that was provided upon knowledge session generation), and that spawns a signal:
{code}
ksession.signalEvent("Signal", null);
{code}
When signal is sent, it effectively runs all process instances into completion, and that is OK.
But when I have for example more stateful sessions persisted, and each has its own set of processes, calling {code}ksession.signalEvent("Signal", null);{code} runs processes from all sessions into completion, not only the processes that belong to that particular session.
Another thing I've spotted: when I load knowledge session from database, method {code}ksession.getProcessInstances(){code} returns empty list.
That is weird because at the same time method {code}ksession.getProcessInstance(1){code} correctly loads process instance from database.
Thanks,
Miljenko