<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<body link="#355491" alink="#4262a1" vlink="#355491" style="background: #e2e2e2; margin: 0; padding: 20px;">
<div>
        <table cellpadding="0" bgcolor="#FFFFFF" border="0" cellspacing="0" style="border: 1px solid #dadada; margin-bottom: 30px; width: 100%; -moz-border-radius: 6px; -webkit-border-radius: 6px;">
                <tbody>
                        <tr>
                                <td>
                                        <table border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF" style="border: solid 2px #ccc; background: #dadada; width: 100%; -moz-border-radius: 6px; -webkit-border-radius: 6px;">
                                                <tbody>
                                                        <tr>
                                                                <td bgcolor="#000000" valign="middle" height="58px" style="border-bottom: 1px solid #ccc; padding: 20px; -moz-border-radius-topleft: 3px; -moz-border-radius-topright: 3px; -webkit-border-top-right-radius: 5px; -webkit-border-top-left-radius: 5px;">
                                                                        <h1 style="color: #333333; font: bold 22px Arial, Helvetica, sans-serif; margin: 0; display: block !important;">
                                                                        <!-- To have a header image/logo replace the name below with your img tag -->
                                                                        <!-- Email clients will render the images when the message is read so any image -->
                                                                        <!-- must be made available on a public server, so that all recipients can load the image. -->
                                                                        <a href="https://community.jboss.org/index.jspa" style="text-decoration: none; color: #E1E1E1">JBoss Community</a></h1>
                                                                </td>
                                                        </tr>
                                                        <tr>
                                                                <td bgcolor="#FFFFFF" style="font: normal 12px Arial, Helvetica, sans-serif; color:#333333; padding: 20px; -moz-border-radius-bottomleft: 4px; -moz-border-radius-bottomright: 4px; -webkit-border-bottom-right-radius: 5px; -webkit-border-bottom-left-radius: 5px;"><h3 style="margin: 10px 0 5px; font-size: 17px; font-weight: normal;">
No process or session info in database table
</h3>
<span style="margin-bottom: 10px;">
created by <a href="https://community.jboss.org/people/rafaelsoledadem">Rafael Soledade</a> in <i>jBPM</i> - <a href="https://community.jboss.org/message/787027#787027">View the full discussion</a>
</span>
<hr style="margin: 20px 0; border: none; background-color: #dadada; height: 1px;">
<div class="jive-rendered-content"><p>Hi,</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>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!</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>Here's my code so far:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>.java main</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>// Load up the events knowledge base</p><p>                    KnowledgeBase eventKbase = readEventKnowledgeBase();</p><p>                    StatefulKnowledgeSession eventKsession = eventKbase</p><p>                                        .newStatefulKnowledgeSession();</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>                    // Load up the knowledge base</p><p>                    KnowledgeBase kbase = readKnowledgeBase();</p><p>                    StatefulKnowledgeSession ksession = null;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>                    // Settings up JPA persistence</p><p>                    EntityManagerFactory emf = Persistence</p><p>                                        .createEntityManagerFactory("test");</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>                    Environment env = KnowledgeBaseFactory.newEnvironment();</p><p>                    env.set(EnvironmentName.ENTITY_MANAGER_FACTORY, emf);</p><p>                    env.set(EnvironmentName.TRANSACTION_MANAGER,</p><p>                                        TransactionManagerServices.getTransactionManager());</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>                    // create a new knowledge session that uses JPA to store the runtime</p><p>                    // state</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>                    ksession = JPAKnowledgeService.newStatefulKnowledgeSession(kbase, null,</p><p>                                        env);</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>                    // this session id - will have to be stored for recovery of session</p><p>                    int sessionId = ksession.getId();</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>                    System.out.printf("\n-----> Session ID: %d\n", sessionId);</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>                    // loads up the session with sessionId - not sure how to use this yet</p><p>                    // ksession =</p><p>                    // JPAKnowledgeService.loadStatefulKnowledgeSession(sessionId, kbase,</p><p>                    // null, env);</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>                    // uses custom process event listener</p><p>                    ksession.addEventListener(new CustomProcessEventListener(eventKsession));</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>                    // register work items</p><p>                    ksession.getWorkItemManager().registerWorkItemHandler("Notification",</p><p>                                        new MyWorkItemHandler(ksession));</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>                    // start transaction</p><p>                    UserTransaction transaction = (UserTransaction) new InitialContext()</p><p>                                        .lookup("java:comp/UserTransaction");</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>                    transaction.begin();</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>                    // Create the process instance</p><p>                    ProcessInstance processInstance = ksession.createProcessInstance(</p><p>                                        "com.sample.bpmn.hello", null);</p><p>                    System.out.println("\n-----> Starting new Business process "</p><p>                                        + processInstance.getProcessId() + " <ID:" + sessionId + ">\n");</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>                    // Start the BPM process</p><p>                    ksession.startProcessInstance(processInstance.getId());</p><p>                    transaction.commit();</p><p>                    // Did the process instance complete successfully ?</p><p>                    if (processInstance.getState() == ProcessInstance.STATE_COMPLETED) {</p><p>                              System.out.printf("\n-----> Business process "</p><p>                                                  + processInstance.getProcessId() + " <ID:" + sessionId</p><p>                                                  + "> successfully completed\n");</p><p>                    }</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>                    // free resources and end session</p><p>                    emf.close();</p><p>                    ksession.dispose();</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>Custom Work Item Handler:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>public class MyWorkItemHandler implements WorkItemHandler {</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>          private KnowledgeRuntime session;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>          public MyWorkItemHandler() {</p><p>          }</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>          public MyWorkItemHandler(KnowledgeRuntime session) {</p><p>                    this();</p><p>                    this.session = session;</p><p>          }</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>          public void executeWorkItem(WorkItem workItem, WorkItemManager manager) {</p><p>/**</p><p>                    // extract parameters</p><p>                    String from = (String) workItem.getParameter("From");</p><p>                    String to = (String) workItem.getParameter("To");</p><p>                    String message = (String) workItem.getParameter("Message");</p><p>                    String priority = (String) workItem.getParameter("Priority");</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>        // Artificial wait</p><p>        try {</p><p>            Thread.sleep(5000);</p><p>        }</p><p>        catch (Exception ex) {</p><p>        }</p><p>  </p><p>                    System.out.println("###work item handler operations###");</p><p>  </p><p>                    session.getWorkItemManager().completeWorkItem(workItem.getId(), null);</p><p>  </p><p>                    //manager.completeWorkItem(workItem.getId(), null);</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>          }</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>persistence.xml:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p><persistence-unit name="test" transaction-type="JTA"></p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>                    <provider>org.hibernate.ejb.HibernatePersistence</provider></p><p>                    <class>org.jbpm.persistence.processinstance.ProcessInstanceInfo</class></p><p>                    <class>org.drools.persistence.info.SessionInfo</class></p><p>                    <class>org.drools.persistence.info.WorkItemInfo</class></p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>                    <properties></p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>                              <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" /></p><p>                              <property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver" /></p><p>                              <property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306/test" /></p><p>                              <property name="hibernate.connection.username" value="root" /></p><p>                              <property name="hibernate.connection.password" value="12345" /></p><p>                              <property name="hibernate.connection.autocommit" value="false" /></p><p>                              <property name="hibernate.max_fetch_depth" value="3" /></p><p>                              <property name="hibernate.hbm2ddl.auto" value="create" /></p><p>                              <property name="hibernate.show_sql" value="false" /></p><p>                              <property name="hibernate.transaction.manager_lookup_class"</p><p>                                        value="org.hibernate.transaction.BTMTransactionManagerLookup" /></p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>                    </properties></p><p>          </persistence-unit></p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p></persistence></p></div>
<div style="background-color: #f4f4f4; padding: 10px; margin-top: 20px;">
<p style="margin: 0;">Reply to this message by <a href="https://community.jboss.org/message/787027#787027">going to Community</a></p>
        <p style="margin: 0;">Start a new discussion in jBPM at <a href="https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034">Community</a></p>
</div></td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</div>
</body>
</html>