James Williams [http://community.jboss.org/people/williajd] created the 
discussion

"Completing a Task Fails after Calling statefulSession.dispose"

To view the discussion, visit: http://community.jboss.org/message/621863#621863

--------------------------------------------------------------
I have a problem which I think is similar to these but my scenario is slightly 
different. 

How to make a process instance go on with jBPM5?    
 http://community.jboss.org/message/600654#600654 
http://community.jboss.org/message/600654


Human task API, how to move forward in the workflow ?
 http://community.jboss.org/message/614986#614986#614986 
http://community.jboss.org/message/614986#614986


Here is my problem. I create a process using the following:


    Environment env = KnowledgeBaseFactory.newEnvironment();
    env.set(EnvironmentName.ENTITY_MANAGER_FACTORY, entityManagerFactory);
    InitialContext ctx = new InitialContext();
    UserTransaction transactionManager = (UserTransaction) 
ctx.lookup("java:comp/UserTransaction");
    env.set(EnvironmentName.TRANSACTION_MANAGER, transactionManager);

    StatefulKnowledgeSession knowledgeSession = 
JPAKnowledgeService.newStatefulKnowledgeSession(knowledgeBase, null, env);
    WorkItemHandler handler = new 
CommandBasedWSHumanTaskHandler(knowledgeSession);
    knowledgeSession.getWorkItemManager().registerWorkItemHandler("Human Task", 
handler);


    statefulSession.startProcess(processDefinitionId, processVariables);

    statefulSession.dispose(); (Remember this line)

This works fine. The process is created and the first Human Task exists as 
expected.

My next step is to use the Mina Task Client, via the task client to assign and 
complete the task. The assign works perfectly however I get the following 
exception when completing the task.


    SEVERE: Could not commit session
    java.lang.NullPointerException
        at 
org.drools.persistence.jpa.JpaPersistenceContextManager.beginCommandScopedEntityManager(JpaPersistenceContextManager.java:67)
        at 
org.drools.persistence.SingleSessionCommandService.execute(SingleSessionCommandService.java:287)
        at 
org.drools.command.impl.CommandBasedStatefulKnowledgeSession$1.completeWorkItem(CommandBasedStatefulKnowledgeSession.java:149)
        at 
org.jbpm.process.workitem.wsht.CommandBasedWSHumanTaskHandler$GetResultContentResponseHandler.execute(CommandBasedWSHumanTaskHandler.java:295)
        at 
org.jbpm.task.service.TaskClientHandler.messageReceived(TaskClientHandler.java:153)
        at 
org.jbpm.task.service.mina.MinaTaskClientHandler.messageReceived(MinaTaskClientHandler.java:47)
        at 
org.apache.mina.core.filterchain.DefaultIoFilterChain$TailFilter.messageReceived(DefaultIoFilterChain.java:713)


This results in the task being completed but the next task is not created.


This exception is thrown because the 
org.drools.persistence.jpa.JpaPersistenceContextManager.appScopedEntityManager 
is null. This field is initialised when the JpaPersistenceContextManager is 
created and is nulled when the dispose method is called. 


I was able to have the task complete properly by commenting out the call to 
dispose.

     // statefulSession.dispose();

Not a good solution. I can't keep sessions open forever.


The crux of the problem is that when completing the task it attempts to use the 
JpaPersistenceContextManager that was used to create the process, which has 
already been disposed of.


My question is, how do I re-intitialise the JpaPersistenceContextManager to use 
ensure it has an active entityManager? Remember I'm making a call via the Mina 
Task Client so have no access to the JpaPersistenceContextManager.

Any help would be really appreciated.
--------------------------------------------------------------

Reply to this message by going to Community
[http://community.jboss.org/message/621863#621863]

Start a new discussion in jBPM at Community
[http://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]

_______________________________________________
jboss-user mailing list
[email protected]
https://lists.jboss.org/mailman/listinfo/jboss-user

Reply via email to