我正在尝试在部署在 JBoss7 应用服务器上的 jBPMv5.x 上执行一个简单的人工任务 bpmn。数据库是 Postgresql V9.2。我发现任务正在提交给数据库,但即使在调用 ksession.dispose() 之后,sessioninfo 和 processinfo 也永远不会插入到各自的表中。
请让我知道我错过了什么。
持久性.xml
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<persistence version="2.0"
xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://java.sun.com/xml/ns/persistence
http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
<persistence-unit name="org.drools.persistence.jpa"
transaction-type="JTA">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<jta-data-source>java:jboss/datasources/jbpmDS</jta-data-source>
<mapping-file>META-INF/ProcessInstanceInfo.hbm.xml</mapping-file>
<mapping-file>META-INF/ExtraIndexes.hbm.xml</mapping-file>
<mapping-file>META-INF/JBPMorm.xml</mapping-file>
<class>org.jbpm.persistence.processinstance.ProcessInstanceInfo</class>
<class>org.drools.persistence.info.SessionInfo</class>
<class>org.drools.persistence.info.WorkItemInfo</class>
<class>org.jbpm.process.audit.ProcessInstanceLog</class>
<class>org.jbpm.process.audit.NodeInstanceLog</class>
<class>org.jbpm.process.audit.VariableInstanceLog</class>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect" />
<property name="hibernate.default_schema" value="jbpm" />
<property name="hibernate.cache.use_query_cache" value="false" />
<property name="hibernate.show_sql" value="true" />
<property name="hibernate.format_sql" value="true" />
<property name="hibernate.use_sql_comments" value="true" />
<property name="hibernate.transaction.manager_lookup_class"
value="org.hibernate.transaction.JBossTransactionManagerLookup" />
<property name="hibernate.transaction.factory_class"
value="org.hibernate.transaction.JTATransactionFactory" />
<property name="hibernate.transaction.flush_before_completion"
value="false" />
<property name="hibernate.id.new_generator_mappings" value="false" />
</properties>
</persistence-unit>
<persistence-unit name="org.jbpm.task"
transaction-type="JTA">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<jta-data-source>java:jboss/datasources/jbpmDS</jta-data-source>
<mapping-file>META-INF/Taskorm.xml</mapping-file>
<class>org.jbpm.task.Attachment</class>
<class>org.jbpm.task.BooleanExpression</class>
<class>org.jbpm.task.Comment</class>
<class>org.jbpm.task.Content</class>
<class>org.jbpm.task.Deadline</class>
<class>org.jbpm.task.Delegation</class>
<class>org.jbpm.task.EmailNotification</class>
<class>org.jbpm.task.EmailNotificationHeader</class>
<class>org.jbpm.task.Escalation</class>
<class>org.jbpm.task.Group</class>
<class>org.jbpm.task.I18NText</class>
<class>org.jbpm.task.Notification</class>
<class>org.jbpm.task.OnAllSubTasksEndParentEndStrategy</class>
<class>org.jbpm.task.OnParentAbortAllSubTasksEndStrategy</class>
<class>org.jbpm.task.PeopleAssignments</class>
<class>org.jbpm.task.Reassignment</class>
<class>org.jbpm.task.Status</class>
<class>org.jbpm.task.SubTasksStrategy</class>
<class>org.jbpm.task.Task</class>
<class>org.jbpm.task.TaskData</class>
<class>org.jbpm.task.User</class>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect" />
<property name="hibernate.default_schema" value="jbpm" />
<property name="hibernate.cache.use_query_cache" value="false" />
<property name="hibernate.show_sql" value="true" />
<property name="hibernate.format_sql" value="true" />
<property name="hibernate.use_sql_comments" value="true" />
<property name="hibernate.transaction.manager_lookup_class"
value="org.hibernate.transaction.JBossTransactionManagerLookup" />
<property name="hibernate.transaction.factory_class"
value="org.hibernate.transaction.JTATransactionFactory" />
<property name="hibernate.transaction.flush_before_completion"
value="false" />
<property name="hibernate.id.new_generator_mappings" value="false" />
</properties>
</persistence-unit>
</persistence>
ProcMgmtBean
@TransactionManagement(TransactionManagementType.BEAN)
@Singleton(name = "ProcMgmt")
public class ProcMgmtBean implements IProcMgmt, Serializable {
private static final long serialVersionUID = 1L;
@PersistenceUnit(unitName = "org.jbpm.task")
private EntityManagerFactory emftask;
@PersistenceUnit(unitName = "org.drools.persistence.jpa")
private EntityManagerFactory emfpersist;
public void registerTaskService(StatefulKnowledgeSession ksession) {
Properties properties = getProperties();
System.setProperty("jbpm.usergroup.callback", properties.getProperty(
"taskservice.usergroupcallback",
"org.jbpm.task.service.DefaultUserGroupCallbackImpl"));
System.out.println("Inside register task service, create new task service");
TaskService taskService = new TaskService(emftask,
SystemEventListenerFactory.getSystemEventListener());
System.out.println("Task service instantiated, creating handler");
SyncWSHumanTaskHandler handler = new SyncWSHumanTaskHandler(
new LocalTaskService(taskService), ksession);
handler.connect();
System.out.println("Handler connected");
ksession.getWorkItemManager().registerWorkItemHandler("Human Task",
handler);
System.out.println("Task service registered");
}
protected Environment createEnvironment() {
Environment env = EnvironmentFactory.newEnvironment();
env.set(EnvironmentName.ENTITY_MANAGER_FACTORY, emfpersist);
return env;
}
public StatefulKnowledgeSession newStatefulKnowledgeSession(
KnowledgeBase kbase) {
return loadStatefulKnowledgeSession(kbase, -1);
}
public StatefulKnowledgeSession loadStatefulKnowledgeSession(
KnowledgeBase kbase, int sessionId) {
StatefulKnowledgeSession ksession;
Environment env = createEnvironment();
Properties sessionconfigproperties = new Properties();
sessionconfigproperties.put("drools.processInstanceManagerFactory",
"org.jbpm.process.instance.impl.DefaultProcessInstanceManagerFactory");
sessionconfigproperties.put("drools.processSignalManagerFactory",
"org.jbpm.process.instance.event.DefaultSignalManagerFactory");
KnowledgeSessionConfiguration config = KnowledgeBaseFactory
.newKnowledgeSessionConfiguration(sessionconfigproperties);
if (sessionId == -1) {
System.out.println("session id = -1");
ksession = JPAKnowledgeService.newStatefulKnowledgeSession(kbase,
config, env);
} else {
System.out.println("session id = " + sessionId);
ksession = JPAKnowledgeService.loadStatefulKnowledgeSession(
sessionId, kbase, config, env);
}
return ksession;
}
}
调用 servlet
protected void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
System.out.println("Inside doGet");
initiateWF();
}
private void initiateWF() {
System.out.println("Init");
KnowledgeBase kbase = readKnowledgeBase();
IProcMgmt processMgmt = null;
System.out.println("START OF CREATION OF PROC MANAGEMENT");
try {
Context ctx = new InitialContext();
processMgmt = (IProcMgmt) ctx
.lookup("java:global...");
System.out.println("Proc management created "
+ (processMgmt != null));
} catch (NamingException e1) {
System.out.println("Fail to create Proc mgmt");
e1.printStackTrace();
}
System.out.println("read kb complete");
StatefulKnowledgeSession ksession = processMgmt
.newStatefulKnowledgeSession(kbase);
int sessionId = ksession.getId();
System.out.println("session id:" + sessionId );
System.out
.println("got new ksession, starting to register task service");
processMgmt.registerTaskService(ksession);
System.out.println("task service registered");
// start a new process instance
//Each Command will generate an interaction
System.out.println(">>> Let's Create Process Instance");
ProcessInstance processInstance = ksession.createProcessInstance("com.sample.bpmn.humanhello",null);
System.out.println(">>> Let's Start the Process Instance");
long processInstanceId = processInstance.getId();
System.out.println(" processInstanceId:" + processInstanceId);
String processId = processInstance.getProcessId();
System.out.println(" process id:" + processId);
ksession.startProcess(processId);
System.out.println(">>> Disposing Session");
ksession.dispose();
}
private KnowledgeBase readKnowledgeBase() {
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory
.newKnowledgeBuilder();
kbuilder.add(ResourceFactory
.newClassPathResource("jbpm/com.sample.HumanHello.bpmn2"),
ResourceType.BPMN2);
return kbuilder.newKnowledgeBase();
}