[jboss-user] [jBPM] - No process or session info in database table
Rafael Soledade
do-not-reply at jboss.com
Wed Jan 2 07:20:57 EST 2013
Rafael Soledade [https://community.jboss.org/people/rafaelsoledadem] created the discussion
"No process or session info in database table"
To view the discussion, visit: https://community.jboss.org/message/787027#787027
--------------------------------------------------------------
Hi,
I'm developing a business process flow using jBPM, and so far I've created the BPMN and configured the persistence to work with my database. I've noticed a class mapping in the persistence.xml file for the tables SessionInfo, WorkItemInfo and ProcessInstanceInfo, and they are indeed successfully created in my MySQL schema. The problem is, once I start a new knowledge session and run my process instance, nothing is written in those tables, so I can't really restore sessions (not having persistence, then). What am I doing wrong here? Any help would be appreciated!
Here's my code so far:
.java main
// Load up the events knowledge base
KnowledgeBase eventKbase = readEventKnowledgeBase();
StatefulKnowledgeSession eventKsession = eventKbase
.newStatefulKnowledgeSession();
// Load up the knowledge base
KnowledgeBase kbase = readKnowledgeBase();
StatefulKnowledgeSession ksession = null;
// Settings up JPA persistence
EntityManagerFactory emf = Persistence
.createEntityManagerFactory("test");
Environment env = KnowledgeBaseFactory.newEnvironment();
env.set(EnvironmentName.ENTITY_MANAGER_FACTORY, emf);
env.set(EnvironmentName.TRANSACTION_MANAGER,
TransactionManagerServices.getTransactionManager());
// create a new knowledge session that uses JPA to store the runtime
// state
ksession = JPAKnowledgeService.newStatefulKnowledgeSession(kbase, null,
env);
// this session id - will have to be stored for recovery of session
int sessionId = ksession.getId();
System.out.printf("\n-----> Session ID: %d\n", sessionId);
// loads up the session with sessionId - not sure how to use this yet
// ksession =
// JPAKnowledgeService.loadStatefulKnowledgeSession(sessionId, kbase,
// null, env);
// uses custom process event listener
ksession.addEventListener(new CustomProcessEventListener(eventKsession));
// register work items
ksession.getWorkItemManager().registerWorkItemHandler("Notification",
new MyWorkItemHandler(ksession));
// start transaction
UserTransaction transaction = (UserTransaction) new InitialContext()
.lookup("java:comp/UserTransaction");
transaction.begin();
// Create the process instance
ProcessInstance processInstance = ksession.createProcessInstance(
"com.sample.bpmn.hello", null);
System.out.println("\n-----> Starting new Business process "
+ processInstance.getProcessId() + " <ID:" + sessionId + ">\n");
// Start the BPM process
ksession.startProcessInstance(processInstance.getId());
transaction.commit();
// Did the process instance complete successfully ?
if (processInstance.getState() == ProcessInstance.STATE_COMPLETED) {
System.out.printf("\n-----> Business process "
+ processInstance.getProcessId() + " <ID:" + sessionId
+ "> successfully completed\n");
}
// free resources and end session
emf.close();
ksession.dispose();
Custom Work Item Handler:
public class MyWorkItemHandler implements WorkItemHandler {
private KnowledgeRuntime session;
public MyWorkItemHandler() {
}
public MyWorkItemHandler(KnowledgeRuntime session) {
this();
this.session = session;
}
public void executeWorkItem(WorkItem workItem, WorkItemManager manager) {
/**
// extract parameters
String from = (String) workItem.getParameter("From");
String to = (String) workItem.getParameter("To");
String message = (String) workItem.getParameter("Message");
String priority = (String) workItem.getParameter("Priority");
// Artificial wait
try {
Thread.sleep(5000);
}
catch (Exception ex) {
}
System.out.println("###work item handler operations###");
session.getWorkItemManager().completeWorkItem(workItem.getId(), null);
//manager.completeWorkItem(workItem.getId(), null);
}
persistence.xml:
<persistence-unit name="test" transaction-type="JTA">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<class>org.jbpm.persistence.processinstance.ProcessInstanceInfo</class>
<class>org.drools.persistence.info.SessionInfo</class>
<class>org.drools.persistence.info.WorkItemInfo</class>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" />
<property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver" />
<property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306/test" />
<property name="hibernate.connection.username" value="root" />
<property name="hibernate.connection.password" value="12345" />
<property name="hibernate.connection.autocommit" value="false" />
<property name="hibernate.max_fetch_depth" value="3" />
<property name="hibernate.hbm2ddl.auto" value="create" />
<property name="hibernate.show_sql" value="false" />
<property name="hibernate.transaction.manager_lookup_class"
value="org.hibernate.transaction.BTMTransactionManagerLookup" />
</properties>
</persistence-unit>
</persistence>
--------------------------------------------------------------
Reply to this message by going to Community
[https://community.jboss.org/message/787027#787027]
Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/jboss-user/attachments/20130102/0a6857b6/attachment-0001.html
More information about the jboss-user
mailing list