[rules-users] Persistence with Drools 5.0.1 (was Persistence with Drools 5.1.0.M2)
Rory Farrell
rjf at bellsouth.net
Sat Jul 24 19:04:14 EDT 2010
I originally had:
manager.completeWorkItem(workItem.getId(), results);
but I changed it to see if it would make a difference.
I get the ksession reference and store it in the constructor of the work
item handler:
WorkItemHandler handler = new MyWorkItemHandler(ksession);
ksession.getWorkItemManager().registerWorkItemHandler("Human Task",
handler);
public MyWorkItemHandler(StatefulKnowledgeSession ksession) {
this.ksession = ksession;
}
Regards,
Rory
On 7/24/2010 8:42 AM, Mauricio Salatino wrote:
> did you try replacing:
> ksession.getWorkItemManager()
> .completeWorkItem(workItem.getId(), results);
>
> for
>
> manager.completeWorkItem(workItem.getId(), results);
> ?
>
> where do you get the ksession reference?
>
> Greetings
>
>
> 2010/7/23 Rory Farrell <rjf at bellsouth.net <mailto:rjf at bellsouth.net>>
>
> Hi, I was trying to get persistence working in Drools 5.1.0.M2 but
> ran into some issues:
>
> http://drools-java-rules-engine.46999.n3.nabble.com/Persistence-with-Drools-5-1-0-M2-td973691.html#none
>
> I decided to try with 5.0.1 to see if I had any better luck. I ran
> into the same problem:
>
> java.lang.NullPointerException
> at
> org.drools.persistence.processinstance.JPAWorkItemManager.completeWorkItem(JPAWorkItemManager.java:85)
>
> Line 85 is:
>
> workItemInfo = em.find(WorkItemInfo.class, id);
>
> The JPAWorkItemManager tries to retrieve the EntityManager from the
> environment:
>
> EntityManager em = (EntityManager)
> this.workingMemory.getEnvironment().get(
> EnvironmentName.ENTITY_MANAGER );
>
> and the EntityManager is not in the environment.
>
> The EntityManagerFactory is in the environment and I see where the
> SingleSessionCommandService class uses the factory to instantiate an
> EntityManager, but it never gets put in the environment for the
> JPAWorkItemManager to retrieve it.
>
> I was using the UIWorkItemHandler from the example applications. I
> wrote a dummy WorkItemHandler to replace the UIWorkItemHandler:
>
> public void executeWorkItem(WorkItem workItem, WorkItemManager
> manager) {
> Map<String, Object> results = new HashMap<String, Object>();
> System.out.println("Before complete work item");
> ksession.getWorkItemManager().completeWorkItem(workItem.getId(),
> results);
> System.out.println("After complete work item");
> }
>
> This fixed the NullPointerException but the role flow process was
> not detecting that the work item had been completed. I debugged
> into the completeWorkItem code and I found that JPAWorkItemManager
> class called the ProcessInstance.signalEvent method with
> "workItemCompleted" but the WorkflowProcessInstanceImpl.signalEvent
> method found no eventListeners for that type.
>
> I can see the eventListeners for "workItemCompleted" and for
> "workItemAborted" when I do a ksession.update but the eventListeners
> are not there when my WorkItemHandler is called.
>
> This only happens when the flow is resumed from an Event Wait flow
> by updating a FactHandle. If the flow goes directly to the Human
> Task node then the workItem is completed correctly.
>
> I attached a screenshot of the rule flow. If there are no missing
> certification when the process is started then the Human Task is
> completed successfully. If there are missing certifications and
> then the constraint is satisfied by updating a FactHandle then the
> workItem is not completed correctly and the flow does not proceed to
> sending the email.
>
> This all works correctly if I don't try to persist the rule flow.
>
> Hopefully someone can provide some insight as to what is going on here.
>
> Regards,
> Rory
>
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org <mailto:rules-users at lists.jboss.org>
> https://lists.jboss.org/mailman/listinfo/rules-users
>
>
>
>
> --
> - CTO @ http://www.plugtree.com
> - MyJourney @ http://salaboy.wordpress.com
> - Co-Founder @ http://www.jbug.com.ar
>
> - Salatino "Salaboy" Mauricio -
>
>
>
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
More information about the rules-users
mailing list