<!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;">
    Muliplt Ksessions | event is not getting dispatched to the StatefulKnowledgeSession
</h3>
<span style="margin-bottom: 10px;">
    created by <a href="https://community.jboss.org/people/ahmedza">Zahid Ahmed</a> in <i>jBPM</i> - <a href="https://community.jboss.org/message/808115#808115">View the full discussion</a>
</span>
<hr style="margin: 20px 0; border: none; background-color: #dadada; height: 1px;">

<div class="jive-rendered-content"><p>*<em>strong text</em>*What could be the problem if the task-completed event is not getting dispatched to the StatefulKnowledgeSession ?</p><p>For a new process-instance, I do</p><ul><li>create a new session&#160; <p>register human-task local GenericHTWorkItemHandler</p><p>register custom event listeners</p><p>call <code>startProcess(processDefinitionId,parameters);</code></p></li></ul><p>It starts a new instance, creates the first human-task via the registered human-task-handler.</p><p>When I want to complete the human-task, I do</p><ul><li>restore the KnowledgeSession with <code>JPAKnowledgeService.loadStatefulKnowledgeSession(lastSessionId,kBase,null, env);</code>&#160; <p>again register human-task local GenericHTWorkItemHandler</p><p>again register custom event listeners</p></li></ul><p>Then call taskService.completeTask, BUT the task-completed is not dispatched to the KnowledgeSession. And the process-flow is not happening</p><p>Should I not register the event listeners again ? Should I not register the work-item-handlers again ?</p><p><strong>Update 1</strong> Exception trace:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><code>07:52:09,618 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/workflow-console].[rsservlet]] (http--0.0.0.0-8280-15) Servlet.service() for servlet rsservlet threw exception: java.lang.IllegalStateException: EntityManager is closed<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; at org.hibernate.ejb.AbstractEntityManagerImpl.joinTransaction(AbstractEntityManagerImpl.java:1158) [hibernate-entitymanager-4.0.1.Final.jar:4.0.1.Final]<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; at org.drools.container.spring.beans.persistence.DroolsSpringJpaManager.getApplicationScopedPersistenceContext(DroolsSpringJpaManager.java:89) [drools-spring-5.5.0.Final.jar:5.5.0.Final]<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; at org.drools.persistence.SingleSessionCommandService.execute(SingleSessionCommandService.java:350) [drools-persistence-jpa-5.5.0.Final.jar:5.5.0.Final]<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; at org.drools.command.impl.CommandBasedStatefulKnowledgeSession.getEnvironment(CommandBasedStatefulKnowledgeSession.java:478) [drools-core-5.5.0.Final.jar:5.5.0.Final]<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; at org.jbpm.process.workitem.wsht.GenericHTWorkItemHandler$TaskCompletedHandler.handleCompletedTask(GenericHTWorkItemHandler.java:260) [jbpm-human-task-core-5.4.0.Final.jar:5.4.0.Final]<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; at org.jbpm.process.workitem.wsht.GenericHTWorkItemHandler$TaskCompletedHandler.execute(GenericHTWorkItemHandler.java:234) [jbpm-human-task-core-5.4.0.Final.jar:5.4.0.Final]<br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; at org.jbpm.task.service.local.LocalTaskService$SimpleEventTransport.trigger(LocalTaskService.java:329) [jbpm-human-task-core-5.4.0.Final.jar:5.4.0.Final]</code></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>When reloading a session I am registering new HumanTaskWorkItemhandlers.It keeps on registering event handlers with the TaskService.</p><p>When I connect the workItemHandlers, they register eventHandlers with the taskService. When will this eventHandlers get de-registered from the taskService ?</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><span class="comment-copy">Environment:JBPM 5.4.0.Final, Drools 5.5.0.Final, Jboss 7.1.0.Final</span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><span class="comment-copy">I debugged through the code, task-completed-event was dispatched to more than 1 session.It must be a problem with my ksession management.I created the GenericHTWorkItemHandler with <code>owningKSessionOnly=true&#160; but this didn't worked.</code></span></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/808115#808115">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>