Help using persistence with JBPM 5.4
doboss Jan 2, 2013 9:18 AMCan someone give me some concrete steps on how to implmenet database persistence of the workflow state in JBPM 5.4?
My end goal is to be able to have save points in my process so I can come back to it and restart it where it left off. I have managed to create a very simple web app which can pull a JBPM process from Guvnor and run it. But every time I try to add persistence stuff, the app stops deploying and complains about missing datasources and/or persistence units.
My setup is JBPM 5.4, with the Guvnor and JBPM Console all running on the same JBoss 7.1.1 instance. I have my jdbc drivers properly deployed in JBoss as a module as well.
Attached is my simple web app. If somone could tell me what the next parts to add are to make persistence happen, that would be great.
For those who do not want to download the zip, here is the meat of the code I am running:
{code}
package org.jboss.jbpm.webapp;
import java.util.HashMap;
import java.util.Map;
import javax.ejb.Singleton;
import javax.inject.Named;
import org.drools.KnowledgeBase;
import org.drools.builder.KnowledgeBuilder;
import org.drools.builder.KnowledgeBuilderFactory;
import org.drools.builder.ResourceType;
import org.drools.io.ResourceFactory;
import org.drools.io.impl.UrlResource;
import org.drools.runtime.StatefulKnowledgeSession;
import org.jbpm.examples.quickstarts.Person;
@Singleton
@Named
public class Runner
{
private int timesRun = 0;
private KnowledgeBase kbase = null;
public void runIt()
{
try
{
if (kbase == null)
{
// load up the knowledge base
kbase = readKnowledgeBase();
}
StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();
Map<String, Object> params = new HashMap<String, Object>();
Person p = new Person("Maciej Swiderski");
params.put("person", p);
ksession.startProcess("com.sample.script", params);
}
catch (Throwable t)
{
t.printStackTrace();
}
timesRun++;
}
private static KnowledgeBase readKnowledgeBase() throws Exception
{
String url = "http://localhost:8080/drools-guvnor/org.drools.guvnor.Guvnor/package/defaultPackage/LATEST";
UrlResource resource = (UrlResource) ResourceFactory.newUrlResource(url);
resource.setBasicAuthentication("enabled");
resource.setUsername("guest");
resource.setPassword("guest");
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add(resource, ResourceType.PKG);
return kbuilder.newKnowledgeBase();
}
public int getTimesRun()
{
return timesRun;
}
public void setTimesRun(int timesRun)
{
this.timesRun = timesRun;
}
}
{code}
The path I was going down was with the JBPMHelper...
If I modify the pom.xml (to add hibernate-core and jbpm-test) change the code like this:
{code}
public void runIt()
{
try
{
if (kbase == null)
{
JBPMHelper.setupDataSource();
// load up the knowledge base
kbase = readKnowledgeBase();
}
StatefulKnowledgeSession ksession = JBPMHelper.newStatefulKnowledgeSession(kbase);
...
{code}
Then I see deployment problems like this :
{code}
13:26:33,891 INFO [org.jboss.as.server] (DeploymentScanner-threads - 2) JBAS015863: Replacement of deployment "jbpm-web-app.war" by deployment "jbpm-web-app.war" was rolled back with failure message {"JBAS014771: Services with missing/unavailable dependencies" => ["jboss.persistenceunit.\"jbpm-web-app.war#org.jbpm.persistence.jpa\"jboss.naming.context.java.jdbc.jbpm-dsMissing[jboss.persistenceunit.\"jbpm-web-app.war#org.jbpm.persistence.jpa\"jboss.naming.context.java.jdbc.jbpm-ds]"]}
...
BAS014775:New missing/unsatisfied dependencies:
service jboss.naming.context.java.jdbc.jbpm-ds (missing) dependents: [service jboss.persistenceunit."jbpm-web-app.war#org.jbpm.persistence.jpa"]
{code}
Thanks!
-
jbpm-in-webapp.zip 7.2 KB